note 72423 added to function.fopen
| From: | baptiste dot pillot at atgp dot net | Date: | Thu, 18 Jan 2007 09:56:35 +0000 |
| Subject: | note 72423 added to function.fopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-121877@lists.php.net to get a copy of this message | ||
fopen uses stat cache since PHP5. It could cause problems if you open files in append mode, as the
file pointer will point on last known end of file, and does not check if the file is bigger.
Example :
// first call creates the file an set position to zero
$f = fopen("filename.txt", "a");
fputs($f, "Hello World\n");
fclose($f);
// PHP4 : second call opens the file and points on end
// PHP5 : second call opens the file and points on zero !
// you should do a clearstatcache(); here
$f = fopen("filename.txt", "a");
fputs($f, "Second Hello World over\n");
fclose($f);
// result in PHP5 : the file only contains "Hello World over"
----
Server IP: 217.174.196.197
Probable Submitter: 193.252.107.244
----
Manual Page -- http://www.php.net/manual/en/function.fopen.php
Edit -- https://master.php.net/note/edit/72423
Del: integrated -- https://master.php.net/note/delete/72423/integrated
Del: useless -- https://master.php.net/note/delete/72423/useless
Del: bad code -- https://master.php.net/note/delete/72423/bad+code
Del: spam -- https://master.php.net/note/delete/72423/spam
Del: non-english -- https://master.php.net/note/delete/72423/non-english
Del: in docs -- https://master.php.net/note/delete/72423/in+docs
Del: other reasons-- https://master.php.net/note/delete/72423
Reject -- https://master.php.net/note/reject/72423
Search -- https://master.php.net/manage/user-notes.php