php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33027 PHP thinks it gets a flock when it doesn't
Submitted: 2005-05-13 15:38 UTC Modified: 2005-05-14 01:09 UTC
From: jaa at interflow dot dk Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.0.4 OS: Un*x
Private report: No CVE-ID: None
 [2005-05-13 15:38 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-13 16:03 UTC] sniper@php.net
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-14 01:09 UTC] jaa at interflow dot dk
I've run tests on both Linux and FreeBSD and flock() is working correctly on both platforms. I'm closing the bug. Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 04 18:01:30 2024 UTC