#31363 [NoF->Opn]: Non-blocking flock() broken
| From: | ian at snork dot net | Date: | Wed, 09 Mar 2005 16:29:57 +0000 |
| Subject: | #31363 [NoF->Opn]: Non-blocking flock() broken | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-75177@lists.php.net to get a copy of this message | ||
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] sniper@php.net
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