Doc #51771 [Opn->Csd]: fclose() seems not to unlock the file

From: Date: Fri, 14 May 2010 07:43:43 +0000
Subject: Doc #51771 [Opn->Csd]: fclose() seems not to unlock the file
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-4370@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51771&edit=1 ID: 51771 Updated by: degeberg@php.net Reported by: kulakov74 at yandex dot ru Summary: fclose() seems not to unlock the file -Status: Open +Status: Closed Type: Documentation Problem Package: Filesystem function related Operating System: Linux PHP Version: 5.3.2 -Assigned To: +Assigned To: degeberg New Comment: This bug has been fixed in SVN. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2010-05-14 09:43:25] degeberg@php.net Automatic comment from SVN on behalf of degeberg Revision: http://svn.php.net/viewvc/?view=revision&revision=299368 Log: Fixed PHP bug #51771 (fclose() seems not to unlock the file) ------------------------------------------------------------------------ [2010-05-12 07:20:10] kulakov74 at yandex dot ru Ah thanks then it's only a matter of fixing the documentation for fclock() which still states The lock is released also by fclose() (which is also called automatically when script finished). http://www.php.net/manual/en/function.flock.php ------------------------------------------------------------------------ [2010-05-12 05:41:13] crrodriguez at opensuse dot org Correct, take look at the changelog..it clearly says: "Removed automatic file descriptor unlocking happening on shutdown and/or stream close (on all OSes). (Tony, Ilia)" aka. the correct behaviour. ------------------------------------------------------------------------ [2010-05-08 11:48:04] kulakov74 at yandex dot ru Description: ------------ We have a script that runs in a multiprocess way and it uses flock() for interprocess communication. Things worked fine until we moved to PHP 5.3.2 where all the processes started to hang all of a sudden. I debugged the issues and tried several fixes but they didn't solve it. I made an extensive log of all the script did in order to find out the reason, and I got a situation with 4 scripts running trying to get a non-blocking lock every second, and all of them wrote "lock failed" to the log. At the same time none of them was supposed to hold the lock at that time. Finally I added an flock($hLock, LOCK_UN); before every fclose($hLock); and it is only that that they stopped handing. Test script: --------------- $H=fopen($LockFile, 'a'); flock($H, LOCK_EX); //... //flock($H, LOCK_UN); - the fix fclose($H); Expected result: ---------------- no deadlock Actual result: -------------- Deadlock ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=51771&edit=1

« previous php.doc.bugs (#4370) next »