Edit report at http://bugs.php.net/bug.php?id=54490&edit=1

 ID:                 54490
 Updated by:         ahar...@php.net
 Reported by:        mtdowling at gmail dot com
 Summary:            Add function md5_stream
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            hash related
 Operating System:   Mac OS X
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

You can already do this with hash_update_stream() (in conjunction with
hash_init() and hash_final(), of course). I don't think there's any need
for an algorithm-specific function here.


Previous Comments:
------------------------------------------------------------------------
[2011-04-08 03:28:05] mtdowling at gmail dot com

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();



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54490&edit=1

Reply via email to