比较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()

网站备案号:京ICP备11043289号-1 北京市公安局网络备案 海1101084571
版权所有 北京育灵童科技发展有限公司 Copyright © 2002-2024 www.elight.cn, All Rights Reserved