note 5438 deleted from function.flock by jimw

From: Date: Sat, 08 Dec 2001 19:08:09 +0000
Subject: note 5438 deleted from function.flock by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22075@lists.php.net to get a copy of this message
The main reason you would want to *lock* the file is to avoid multi-user *collisions* and *overwrites*. For example, this would be useless: /* Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. */ $fp = fopen(myFile.dat, "w"); if (flock($fp, 2)) { fwrite("my data"); } flock($fp, 3); The fopen is completed (_truncating the file_) *before* the flock() checks for a lock, unless fopen honors flock(). (If it does, then what do they mean by "...which means all accessing programs have to use the same way of locking or it will not work"?) Even so, though slim, if a second process is nearly syncronous and can execute fopen before the first can execute flock, your hosed.

« previous php.notes (#22075) next »