note 90547 added to function.flock

From: Date: Mon, 27 Apr 2009 20:54:09 +0000
Subject: note 90547 added to function.flock
Groups: php.notes 
Request: Send a blank email to php-notes+get-153859@lists.php.net to get a copy of this message
For those who just want to check if a file is available for locking and return immediately (without blocking), use the following syntax: <?php $file = fopen('file.txt', 'w'); if(flock($file, LOCK_EX | LOCK_NB)){ echo 'Got lock, continue writing to file'; // Code to write to file }else{ echo 'File is locked by another process, aborting writing'; // Couldn't obtain the lock immediately } ?> This is a quick, easy way to determine if another process is using the file or not, without blocking your script. ---- Server IP: 209.41.74.194 Probable Submitter: 170.215.143.31 ---- Manual Page -- http://www.php.net/manual/en/function.flock.php Edit -- https://master.php.net/note/edit/90547 Del: integrated -- https://master.php.net/note/delete/90547/integrated Del: useless -- https://master.php.net/note/delete/90547/useless Del: bad code -- https://master.php.net/note/delete/90547/bad+code Del: spam -- https://master.php.net/note/delete/90547/spam Del: non-english -- https://master.php.net/note/delete/90547/non-english Del: in docs -- https://master.php.net/note/delete/90547/in+docs Del: other reasons-- https://master.php.net/note/delete/90547 Reject -- https://master.php.net/note/reject/90547 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153859) next »