note 80006 added to function.flock
| From: | adminifyouwantbloodde at osu1 dot php dot net | Date: | Mon, 24 Dec 2007 03:05:17 +0000 |
| Subject: | note 80006 added to function.flock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133963@lists.php.net to get a copy of this message | ||
besides from what the manual says about locking a file opendend in w or w+ and using a special lock
file for these cases, you should simply truncate the file yourself with ftruncate() after writing:
<?php
$data='some data';
$handle=fopen('file','r+');
flock($handle,LOCK_EX);
fwrite($handle,$data);
ftruncate($handle,ftell($handle));
flock($handle,LOCK_UN);
fclose($handle);
?>
now the file will have the size of $data without opening the file in w mode but with a lock on the
file.
to the previous writers jpriebe and mallory:
of course the lock is lost in this case, but thats simply because the file is closed by PHP. and
closing the file means unlocking it (same as when you use fclose() yourself).
----
Server IP: 212.124.37.9
Probable Submitter: 84.166.15.92
----
Manual Page -- http://www.php.net/manual/en/function.flock.php
Edit -- https://master.php.net/note/edit/80006
Del: integrated -- https://master.php.net/note/delete/80006/integrated
Del: useless -- https://master.php.net/note/delete/80006/useless
Del: bad code -- https://master.php.net/note/delete/80006/bad+code
Del: spam -- https://master.php.net/note/delete/80006/spam
Del: non-english -- https://master.php.net/note/delete/80006/non-english
Del: in docs -- https://master.php.net/note/delete/80006/in+docs
Del: other reasons-- https://master.php.net/note/delete/80006
Reject -- https://master.php.net/note/reject/80006
Search -- https://master.php.net/manage/user-notes.php