From: jaa at interflow dot dk Operating system: Un*x PHP version: 5.0.4 PHP Bug Type: Filesystem function related Bug description: PHP thinks it gets a flock when it doesn't
Description: ------------ flock($fp, LOCK_EX | LOCK_NB) returns true even when $fp is already locked. This happens both on FreeBSD 5.4 and Gentoo Linux and both PHP 5.0.2, 5.0.3 and 5.0.4 exhibits this behaviour but PHP 4.3.11 works as expected. The blocking version: flock($fp, LOCK_EX) works as expected. The workaround is to check the value of the "wouldblock" argument to flock() but this shouldn't be necessary and is not documented in the manual. Reproduce code: --------------- <?php $fp = fopen("/tmp/lock.txt", "w+"); if (flock($fp, LOCK_EX | LOCK_NB )) { print "Got lock @ ".date('H:i:s'); while(1) {} } else { echo "Couldn't lock the file."; } fclose($fp); ?> Expected result: ---------------- When a file is already locked flock($fp, LOCK_EX | LOCK_NB) should return false. First terminal: % ~/php-5.0.4/sapi/cli/php flock.php 15:18:34 Got lock @ 15:18:34 Second terminal: % ~/php-5.0.4/sapi/cli/php flock.php 15:18:33 Couldn't lock the file. Actual result: -------------- First terminal: % ~/php-5.0.4/sapi/cli/php flock.php 15:18:34 Got lock @ 15:18:34 Second terminal: % ~/php-5.0.4/sapi/cli/php flock.php 15:18:33 Got lock @ 15:18:37 -- Edit bug report at http://bugs.php.net/?id=33027&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33027&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33027&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33027&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33027&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33027&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33027&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33027&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33027&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33027&r=support Expected behavior: http://bugs.php.net/fix.php?id=33027&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33027&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33027&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33027&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33027&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33027&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33027&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33027&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33027&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33027&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33027&r=mysqlcfg