Doc #61436 [Opn->Asn]: Missing fflush() in flock() LOCK_EX example

From: Date: Tue, 20 Mar 2012 07:27:57 +0000
Subject: Doc #61436 [Opn->Asn]: Missing fflush() in flock() LOCK_EX example
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8093@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61436&edit=1 ID: 61436 Updated by: aharvey@php.net Reported by: blewis at eatonvance dot com Summary: Missing fflush() in flock() LOCK_EX example -Status: Open +Status: Assigned Type: Documentation Problem -Package: *General Issues +Package: Documentation problem Operating System: Windows 2008 PHP Version: Irrelevant -Assigned To: +Assigned To: aharvey Block user comment: N Private report: N New Comment: That is a really good point. Previous Comments: ------------------------------------------------------------------------ [2012-03-19 14:41:54] blewis at eatonvance dot com Description: ------------ --- From manual page: http://www.php.net/function.flock#refsect1-function.flock- examples --- Example should be modified to add fflush() as below. There is no point in gaining an exclusive lock if you release it before flushing output. <?php $fp = fopen("/tmp/lock.txt", "r+"); if (flock($fp, LOCK_EX)) { // do an exclusive lock ftruncate($fp, 0); // truncate file fwrite($fp, "Write something here\n"); fflush($fp); // flush output before releasing lock flock($fp, LOCK_UN); // release the lock } else { echo "Couldn't get the lock!"; } fclose($fp); ?> Actual result: -------------- Saw a corrupted file that seems to indicate that output is not automatically flushed when an exclusive lock is released. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61436&edit=1

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