This is a discussion on Basic file locking question within the Apache Web Server forums, part of the Web Server and Related Forums category; I've configured apache to fetch filename.htm if user requests filename.htm. But if filename.htm does not exist, ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've configured apache to fetch filename.htm if user requests
filename.htm. But if filename.htm does not exist, apache will call index.php. Now, index.php will generate a page, buffer it and then save it as filename.htm (thus, effectively filename.htm is cached as static file on server hard disk) Every 10 minutes a cron job deletes filename.htm So all users requesting filename.htm would be served with the static version if it exists, otherwise a latest dynamic version created by index.php. Any comments about using this type of caching technique..? Any concurrent read/write problems that anyone foresees? Mike |
|
|||
|
Ignoramus19113 wrote: > yeah, you can find your processes reading half written files. Not > good. > > when you write, do it like this (I do not know PHP, this is > pseudocode): > > F = open_for_writing( "/dir/name/filename.htm.new" ); > write_my_data_to_file(); > close_file( F ); > rename( "/dir/name/filename.htm.new", "/dir/name/filename.htm" ); > This is what I guessed before but was not really sure. Say, a user requests filename.htm and it does not exist. So apache calls index.php, which starts writing to filename.htm. While index.php is writing filename.htm, say another user requests filename.htm. So he will get a half-written file. So you propose that using your rename scheme will definitely eliminate this problem ? Please confirm. Mike > > On 30 Apr 2005 13:53:51 -0700, siliconmike <siliconmike@yahoo.com> wrote: > > I've configured apache to fetch filename.htm if user requests > > filename.htm. But if filename.htm does not exist, apache will call > > index.php. > > > > Now, index.php will generate a page, buffer it and then > > save it as filename.htm (thus, effectively filename.htm is cached as > > static > > file on server hard disk) > > > > Every 10 minutes a cron job deletes filename.htm > > > > So all users requesting filename.htm would be served with the static > > version if it exists, otherwise a latest dynamic version created by > > index.php. > > > > Any comments about using this type of caching technique..? Any > > concurrent read/write problems that anyone foresees? > > > > Mike > > > > > -- |
|
|||
|
> It should. As a second thought, use extension based on process id, not > .new, since two processes could decide to create the same file at the > same time. > How abt this instead of your process id extension proposal? C = check_if_exists("filename.htm.new"); if(!C) { F = open_for_writing( "/dir/name/filename.htm.new" ); if(!F) //in case some other process just opened it for writing { write_my_data_to_file(); close_file( F ); rename( "/dir/name/filename.htm.new", "/dir/name/filename.htm" ); } } I'm still not sure about following possibilities: check_if_exists while writing conflict of .new file deleting while reading of filename.htm Thanks Mike |