[PHP3] File Locking Question From: pnet <email protected>
Date: 09/30/98

Suppose my CGI writes to a file which contains a session_id.

Suppose the browser is trying to create a frameset by calling the cgi to
generate frame1 and frame2 and sends both requests essentially
simultaneously.

Suppose the request for frame1 is handled first, and CGI has the session_id
file open for writing at the same time that the request for frame2 comes
in.
(Another example would be several simultaneous requests for the cgi by
multiple users...)

What is going to happen?

Will PHP report an error "unable to open file..." or will linux suspend the
CGI and keep trying to execute fopen() for awhile before returning an
error?

Do I need to handle such possibilities in my PHP script with something like:
while( ! fopen($fp, "w") );

Related question:

What kind of a file lock is caused by different modes of fopen?
I.e., does any mode lock the file against being opened in any mode?

My script needs to first read the file, then increment the count before
writing it back out. I need to be sure that process2 doesn't try to read
from the file after process1 has read it, but before process1 can increment
it and write the new value back out to the file.

I am running PHP as CGI, if that makes any difference.

Thanks for your help.

- tppt: Tom Paine, Perpetual Traveller; webmaster <email protected>
================================================================
The USA has the highest incarceration rate in the world (1.6 m)
Most of those in prison are there for victimless 'crimes' (63%)
Since 1979, property seized without trial, has increased by 2500%
In the 'War On Drugs', drugs do not die. People do.

--
PHP 3 Mailing List   http://www.php.net/
To unsubscribe send an empty message to php3-unsubscribe <email protected>
To subscribe to the digest list:  php3-digest-subscribe <email protected>
For help: php3-help <email protected>  Archive:  http://www.php.net/mailsearch.php3