脚本宝典收集整理的这篇文章主要介绍了php – 一种使md5_file()更快的方法?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑:使用hash extension(提供增量散列函数)和php5.3+ closure:的quick& dirty示例:
$urls = array( 'https://stackoverflow.COM/','http://sstatic.net/so/img/logo.png','http://www.gravatar.com/avatar/212151980ba7123c314251b185608b1d?s=128&d=identicon&r=PG','http://de.PHP.net/images/PHP.gif' ); $data = array(); $fnWrITe = function($ch,$chunk) use(&$data) { foreach( $data as $d ) { if ( $ch===$d['curlrc'] ) { hash_update($d['hashrc'],$chunk); } } }; $mh = curl_multi_init(); foreach($urls as $u) { $current = curl_init(); curl_setopt($current,CURLOPT_URL,$u); curl_setopt($current,CURLOPT_RETURNtransfer,0); curl_setopt($current,CURLOPT_HEADER,CURLOPT_WRITEFUNCTION,$fnWrite); curl_multi_add_handle($mh,$current); $hash = hash_init('md5'); $data[] = array('url'=>$u,'curlrc'=>$current,'hashrc'=>$hash); } $active = null; //execute the handles do { $mrc = curl_multi_exec($mh,$active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh,$active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } foreach($data as $d) { curl_multi_remove_handle($mh,$d['curlrc']); echo $d['url'],': ',hash_final($d['hashrc'],false),"\n"; } curl_multi_close($mh);
(没有检查结果,但它只是一个起点)
以上是脚本宝典为你收集整理的php – 一种使md5_file()更快的方法?全部内容,希望文章能够帮你解决php – 一种使md5_file()更快的方法?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。