From: murphyk at yahoo-inc dot com
Operating system: RHEL 4.4
PHP version: 5.2.8
PHP Bug Type: PCNTL related
Bug description: children forked with pcntl_fork release flock()s created by
parent
Description:
------------
The behavior of flock()ed files across forks appears to have changed
between php 4.4.8 and php 5.2.8.
Previously, children would inherit filehandles from their parent, and
would close() their copies of the filehandles on exit, but this would not
clear flock()s on the files locked in the parent.
Now, it appears that if any child exits(), this will clear flock()s on any
filehandles inherited from the parent.
Reproduce code:
---------------
<?php
$fp = fopen("/tmp/lock.txt", "w+");
if (flock($fp, LOCK_EX + LOCK_NB )) {
print "Got lock.\n";
} else {
print "Couldn't lock the file.\n";
exit();
}
$pid = pcntl_fork();
if ($pid) {
pcntl_waitpid($pid,$status);
}
else {
exit();
}
sleep(100);
?>
Expected result:
----------------
$ php flock.php &
[1] 22054
$ Got lock.
$ php flock.php
Couldn't lock the file.
Actual result:
--------------
$php flock.php &
[1] 31085
$Got lock.
$php flock.php
Got lock.
--
Edit bug report at http://bugs.php.net/?id=47227&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47227&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47227&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47227&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47227&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47227&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47227&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47227&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47227&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47227&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47227&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47227&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47227&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47227&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47227&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47227&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47227&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47227&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47227&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47227&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47227&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47227&r=mysqlcfg