ID: 31363 User updated by: ian at snork dot net Reported By: ian at snork dot net -Status: No Feedback +Status: Open Bug Type: Filesystem function related Operating System: Debian woody (i386) -PHP Version: 5.0.3 +PHP Version: 5.1.* New Comment:
flock() in today's PHP CVS snapshot (http://snaps.php.net/php5-latest.tar.bz2) behaves slightly differently, but still doesn't quite work correctly in non-blocking mode. Expected result: -------------- $ php5 flock_test.php & Got /tmp/test1 $ php5 flock_test.php & Got /tmp/test2 $ php5 flock_test.php & Got /tmp/test3 $ php5 flock_test.php & $ Releasing /tmp/test1 Got /tmp/test1 Releasing /tmp/test2 Releasing /tmp/test3 Actual result: -------------- $ php5 flock_test.php & Got /tmp/test1 $ php5 flock_test.php & Got /tmp/test2 $ php5 flock_test.php & Got /tmp/test3 $ php5 flock_test.php & $ Releasing /tmp/test1 Releasing /tmp/test2 Releasing /tmp/test3 Previous Comments: ------------------------------------------------------------------------ [2005-03-08 01:00:24] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2005-02-28 21:06:39] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2004-12-31 06:41:56] ian at snork dot net Description: ------------ This code works in PHP 4.3.0, but does not in PHP 5.0.3. When invoked, it will try to lock /tmp/test1, /tmp/test2 or /tmp/test3 for exclusive use, whichever is free. If none are, it will wait a second before cycling through with another attempt. When running concurrently, the first invocation correctly picks up /tmp/test1; the second and subsequent ones just cycle forever. For some reason, the non-blocking flock() only sets $block the first time. Reproduce code: --------------- while (!sleep(1)) foreach (array("/tmp/test1", "/tmp/test2", "/tmp/test3") as $path) if (flock($handle = fopen($path, "w"), LOCK_EX | LOCK_NB, $block) and !$block) { echo "Got $path\n"; sleep(10); echo "Releasing $path\n"; exit; } Expected result: ---------------- $ php5 flock_test.php & Got /tmp/test1 $ php5 flock_test.php & Got /tmp/test2 $ php5 flock_test.php & Got /tmp/test3 $ php5 flock_test.php & Releasing /tmp/test1 Got /tmp/test1 $ Actual result: -------------- $ php5 flock_test.php & Got /tmp/test1 $ php5 flock_test.php & $ php5 flock_test.php & $ php5 flock_test.php & $ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=31363&edit=1
