note 111984 added to function.flock

From: Date: Fri, 19 Apr 2013 00:13:44 +0000
Subject: note 111984 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-194549@lists.php.net to get a copy of this message
you can wrap a lock as an object to make it a scope-based lock. when the lock object is no longer referenced, like when it's unset or the owner returns, the destructor will call unlock. this way you can just create a lock object and forget about it. <?php class lock { private $handle; public static function read ( $handle ) { $lock = new static(); $lock->handle = $handle; return flock($handle,LOCK_SH) ? $lock : false; } public static function write ( $handle ) { $lock = new static(); $lock->handle = $handle; return flock($handle,LOCK_EX) ? $lock : false; } public function __destruct ( ) { flock($this->handle,LOCK_UN); } } ?> ---- Server IP: 69.147.83.199 Probable Submitter: 67.182.168.147 ---- Manual Page -- http://php.net/manual/en/function.flock.php Edit -- https://master.php.net/note/edit/111984 Del: integrated -- https://master.php.net/note/delete/111984/integrated Del: useless -- https://master.php.net/note/delete/111984/useless Del: bad code -- https://master.php.net/note/delete/111984/bad+code Del: spam -- https://master.php.net/note/delete/111984/spam Del: non-english -- https://master.php.net/note/delete/111984/non-english Del: in docs -- https://master.php.net/note/delete/111984/in+docs Del: other reasons-- https://master.php.net/note/delete/111984 Reject -- https://master.php.net/note/reject/111984 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194549) next »