比较file_get_contents与curl运行速度
2017-7-18 dingshangchao php开发
<?php $url = "http://www.jquerycn.cn/a_17252"; $time1 = microtime(true); file_get_contents($url); $time2 = microtime(true); echo $time2-$time1; echo '<br />'; function curl_file_get_contents($durl){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $durl); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $r = curl_exec($ch); curl_close($ch); return $r; } $time1 = microtime(true); curl_file_get_contents($url); $time2 = microtime(true); echo $time2-$time1;
运行结果:
3.2397041320801
1.6480438709259
结论:
一般来说从运行速度方面看用curl优于file_get_content()
« 左滑删除按钮
|
jquery.cookie.js»