note 62004 added to function.flock

From: Date: Fri, 17 Feb 2006 05:50:19 +0000
Subject: note 62004 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-103880@lists.php.net to get a copy of this message
You should never have to write code like this: <?php while(!($canWrite=flock($f, LOCK_EX))) { usleep(2000); } // go ahead and use file fwrite(...); fclose($f); ?> This absolutely defeats the purpose of OS-supported locks, and what's worse is if you specify LOCK_NB, it eats up your CPU time. The following code will work the same way: <?php // this will automatically block, that is, PAUSE until the lock is released flock($f, LOCK_EX) or die("Error getting lock!"); // go ahead and use file fwrite(...); fclose($f); ?> I'm not sure what these people creating spin/sleep loops are doing. ---- Server IP: 210.138.109.182 Probable Submitter: 61.195.156.129 ---- Manual Page -- http://www.php.net/manual/en/function.flock.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62004 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62004&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62004&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#103880) next »