From:             
Operating system: Mac OS X
PHP version:      5.3.6
Package:          hash related
Bug Type:         Feature/Change Request
Bug description:Add function md5_stream

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 bug report at http://bugs.php.net/bug.php?id=54490&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=54490&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=54490&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=54490&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=54490&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=54490&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=54490&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=54490&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=54490&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=54490&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=54490&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=54490&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=54490&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=54490&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=54490&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54490&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54490&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=54490&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=54490&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=54490&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=54490&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=54490&r=mysqlcfg

Reply via email to