note 125826 added to function.readfile
| From: | simbiat at outlook dot com | Date: | Mon, 15 Feb 2021 08:28:06 +0000 |
| Subject: | note 125826 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219211@lists.php.net to get a copy of this message | ||
flobee.at.gmail.dot.com shared "readfile_chunked" function. It does work, but you may
encounter memory exhaustion using "fread". Meanwhile "stream_copy_to_stream"
seems to utilize the same amount of memory as "readfile". At least, when I was testing
"download" function for my https://github.com/Simbiat/HTTP20 library on 1.5G file
with 256M memory limitation that was the case: "fread" I got peak memory usage of ~240M,
while with "stream_copy_to_stream" - ~150M.
It does not mean that you can fully escape memory exhaustion, though: if you are reading too much at
a time, you can still encounter it. That is why in my library I use a helper function
("speedLimit") to calculate whether selected speed limit will fit the available memory
(while allowing some headroom).
You can read comments in the code itself for more details and raise issues for the library, if you
think something is incorrect there (especially since it's WIP at the moment of writing this),
but so far I am able to get consistent behavior with it.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.246 (proxied: 37.204.53.235)
----
Manual Page -- http://php.net/manual/en/function.readfile.php
Edit -- https://master.php.net/note/edit/125826
Del: integrated -- https://master.php.net/note/delete/125826/integrated
Del: useless -- https://master.php.net/note/delete/125826/useless
Del: bad code -- https://master.php.net/note/delete/125826/bad+code
Del: spam -- https://master.php.net/note/delete/125826/spam
Del: non-english -- https://master.php.net/note/delete/125826/non-english
Del: in docs -- https://master.php.net/note/delete/125826/in+docs
Del: other reasons-- https://master.php.net/note/delete/125826
Reject -- https://master.php.net/note/reject/125826
Search -- https://master.php.net/manage/user-notes.php