From: ian at snork dot net
Operating system: Debian woody (i386)
PHP version: 5.0.3
PHP Bug Type: Filesystem function related
Bug description: Non-blocking flock() broken
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 bug report at http://bugs.php.net/?id=31363&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31363&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31363&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31363&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31363&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31363&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31363&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31363&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31363&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31363&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31363&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31363&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31363&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31363&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31363&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31363&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31363&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31363&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31363&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31363&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31363&r=mysqlcfg