note 16828 deleted from function.flock by jimw

From: Date: Sat, 08 Dec 2001 19:10:36 +0000
Subject: note 16828 deleted from function.flock by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22088@lists.php.net to get a copy of this message
Perhaps this is showing my age, but older UNIX systems did the append style locking with a separate file. Like this: function file_lock( $filename, $mode ) { $lock = fopen( $filename . ".lock", "a" ); if (!$lock) return NULL; if (!flock( $lock, $mode )) { fclose($lock); return NULL; } return $lock; } function file_unlock( $lock ) { flock( $lock, LOCK_UN ); fclose( $lock ); } // writer $lock = file_lock( "real.file", LOCK_EX+LOCK_NB ); if ($lock) { ... file_unlock($lock); } // reader $lock = file_lock( "real.file", LOCK_SH+LOCK_NB ); if ($lock) { ... file_unlock($lock); }

« previous php.notes (#22088) next »