#31363 [Opn->Fbk]: Non-blocking flock() broken
| From: | sniper@php.net | Date: | Mon, 28 Feb 2005 20:06:41 +0000 |
| Subject: | #31363 [Opn->Fbk]: Non-blocking flock() broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-76954@lists.php.net to get a copy of this message | ||
ID: 31363
Updated by: sniper@php.net
Reported By: ian at snork dot net
-Status: Open
+Status: Feedback
Bug Type: Filesystem function related
Operating System: Debian woody (i386)
PHP Version: 5.0.3
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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