|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-04-08 09:52 UTC] aharvey@php.net
-Status: Open
+Status: Wont fix
[2011-04-08 09:52 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
Description: ------------ When calculating a MD5 hash using the contents of a PHP stream, we currently need to load the entire stream contents into a string then use the md5() function. Loading the contents of a stream into a string can potentially use a large amount of memory. md5_file() is great for working with registered stream wrappers, but does not allow developers to use an already open stream. md5_file will open a stream, read 1,024 byte chunks to calculate the hash, and then close the stream. I think it would be beneficial to add a md5_stream() function. The md5_stream() function would be identical to md5_file(), but it would calculate the MD5 hash using the contents of an already opened PHP stream. The attached test script shows the current memory drawbacks of calculating the md5 hash using the contents of a large stream. Test script: --------------- <?php $f = fopen('php://temp/maxmemory:32', 'r+'); $filler = implode('', range('A', 'Z')); for ($i = 0; $i < 10000; $i++) { fwrite($f, $filler); } fseek($f, 0); $contents = stream_get_contents($f); $hash = md5($contents); fclose($f); echo memory_get_peak_usage();