note 73887 added to function.fread
| From: | eggbird at bigfoot dot com | Date: | Wed, 14 Mar 2007 17:23:10 +0000 |
| Subject: | note 73887 added to function.fread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124443@lists.php.net to get a copy of this message | ||
Since a fairly recent php (at least it's the case on 5.2.1), fread's memory behaviour
changed.
I used to be able to do things like
<?php
$s = fread($fp, 23985798219384);
?>
to read an entire file, as long as I was sure the file would not be more than 23985798219384 bytes
long. This worked like a charm (and as documented), but since recently, PHP tries to allocate
23985798219384 bytes no matter what. So, if you get memory allocation errors, replace such code by
something like
<?php
$s = fread($fp, filesize($f));
?>
or even
<?php
$s = file_get_contents($f);
?>
.
----
Server IP: 83.137.20.120
Probable Submitter: 131.155.199.103
----
Manual Page -- http://www.php.net/manual/en/function.fread.php
Edit -- https://master.php.net/note/edit/73887
Del: integrated -- https://master.php.net/note/delete/73887/integrated
Del: useless -- https://master.php.net/note/delete/73887/useless
Del: bad code -- https://master.php.net/note/delete/73887/bad+code
Del: spam -- https://master.php.net/note/delete/73887/spam
Del: non-english -- https://master.php.net/note/delete/73887/non-english
Del: in docs -- https://master.php.net/note/delete/73887/in+docs
Del: other reasons-- https://master.php.net/note/delete/73887
Reject -- https://master.php.net/note/reject/73887
Search -- https://master.php.net/manage/user-notes.php