note 112831 added to function.file-put-contents

From: Date: Sun, 28 Jul 2013 11:13:13 +0000
Subject: note 112831 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-195793@lists.php.net to get a copy of this message
It's important to understand that LOCK_EX will not prevent reading the file unless you also explicitly acquire a read lock (shared locked) with the PHP 'flock' function. i.e. in concurrent scenarios file_get_contents may return empty if you don't wrap it like this: <?php $myfile=fopen('test.txt','rt'); flock($myfile,LOCK_SH); $read=file_get_contents('test.txt'); fclose($myfile); ?> If you have code that does a file_get_contents on a file, changes the string, then re-saves using file_put_contents, you better be sure to do this correctly or your file will randomly wipe itself out. ---- Server IP: 69.147.83.199 Probable Submitter: 109.158.147.220 ---- Manual Page -- http://php.net/manual/en/function.file-put-contents.php Edit -- https://master.php.net/note/edit/112831 Del: integrated -- https://master.php.net/note/delete/112831/integrated Del: useless -- https://master.php.net/note/delete/112831/useless Del: bad code -- https://master.php.net/note/delete/112831/bad+code Del: spam -- https://master.php.net/note/delete/112831/spam Del: non-english -- https://master.php.net/note/delete/112831/non-english Del: in docs -- https://master.php.net/note/delete/112831/in+docs Del: other reasons-- https://master.php.net/note/delete/112831 Reject -- https://master.php.net/note/reject/112831 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195793) next »