#31363 [Com]: Non-blocking flock() broken

From: Date: Fri, 01 Apr 2005 12:42:20 +0000
Subject: #31363 [Com]: Non-blocking flock() broken
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-76165@lists.php.net to get a copy of this message
 ID:               31363
 Comment by:       maka3d at yahoo dot com dot br
 Reported By:      ian at snork dot net
 Status:           Open
 Bug Type:         Filesystem function related
 Operating System: Debian woody (i386)
 PHP Version:      5CVS-2005-03-09
 New Comment:

I expected it to be fixed until 5.0.4.
On freeBSD it doesn't work too :(


Previous Comments:
------------------------------------------------------------------------

[2005-03-09 17:29:56] ian at snork dot net

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

------------------------------------------------------------------------

[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


Thread (13 messages)

« previous php.bugs (#76165) next »