note 62004 deleted from function.flock by danbrown

From: Date: Mon, 18 May 2009 00:39:15 +0000
Subject: note 62004 deleted from function.flock by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155406@lists.php.net to get a copy of this message
Note Submitter: dranger AT export dash japan dot com ---- 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.

« previous php.notes (#155406) next »