Basic file locking question

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, ...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-30-2005
siliconmike
 
Posts: n/a
Default Basic file locking question

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

  #2 (permalink)  
Old 05-01-2005
siliconmike
 
Posts: n/a
Default Re: Basic file locking question


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
> >

>
>
> --


  #3 (permalink)  
Old 05-01-2005
siliconmike
 
Posts: n/a
Default Re: Basic file locking question


> 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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:28 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0