ID: 33027 User updated by: jaa at interflow dot dk Reported By: jaa at interflow dot dk -Status: Feedback +Status: Closed Bug Type: Filesystem function related Operating System: Un*x PHP Version: 5.0.4 New Comment:
I've run tests on both Linux and FreeBSD and flock() is working correctly on both platforms. I'm closing the bug. Thanks. Previous Comments: ------------------------------------------------------------------------ [2005-05-13 16:03:58] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-STABLE-latest.tar.gz For Windows: http://snaps.php.net/win32/php5.0-win32-latest.zip Something related to flock() was just fixed this week.. ------------------------------------------------------------------------ [2005-05-13 15:38:35] jaa at interflow dot dk 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 this bug report at http://bugs.php.net/?id=33027&edit=1