|
Posted by abrtlt on 05/04/06 23:23
Thanks. It's a server running on Linux.
Andrew
jon.tjemsland@gmail.com ha scritto:
> What OS is the server that this script is running on? Flock will work
> to lock a file if you are running your script on a server with an OS
> that is compatible with flock. Both NFS and FAT file systems are
> incompatible.
>
> Here is a flock sample from (http://us3.php.net/flock):
>
> $fp = fopen("/tmp/lock.txt", "w+");
> if (flock($fp, LOCK_EX)) { // do an exclusive lock
> fwrite($fp, "Write something here\n");
> flock($fp, LOCK_UN); // release the lock
> } else {
> echo "Couldn't lock the file !";
> }
> fclose($fp);
>
>
> Regards
>
> Jon Tjemsland
>
>
> abrtlt@yahoo.com wrote:
> > I read in Programming PHP (O'Reilly) that flock() "cannot prevent two
> > PHP scripts running in the same web server process from accessing a
> > file at the same time".
> > In my case a single PHP script appends text strings to an existing text
> > file. Several clients may trigger the same script on the same web page
> > and thus more than one PHP instance might try to open and append text
> > to the same file at the same time. I would assume that using flock()
> > _does_ in fact prevent simultaneous access in this case. Am I correct?
> > Thanks!
> >
> > Andrew
Navigation:
[Reply to this message]
|