測試代碼
<?php
function sendGetByCurl($url, $time)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $time);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $time);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
$url = 'http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIrQKRNquic8GwsU951TC7PDCFzIew3RFwTOFoNx8u1fln0FOzHv04YBoEqXPTHHfyU0Xa1qoFULCw/132';
$start1 = microtime(true);
$data1 = file_get_contents($url);
file_put_contents('1.jpg', $data1);
$end1 = microtime(true);
$span1 = $end1 - $start1;
echo $span1 . PHP_EOL;
$start2 = microtime(true);
$data2 = sendGetByCurl($url, 3);
file_put_contents('2.jpg', $data2);
$end2 = microtime(true);
$span2 = $end2 - $start2;
echo $span2 . PHP_EOL;
exit;
測試結(jié)果
16.397258043289
0.18160080909729
那張圖片瀏覽器訪問或者wget下載都很快的,很奇怪
2 回答

偶然的你
TA貢獻1841條經(jīng)驗 獲得超3個贊
這是file_get_contents的一個bug,在最新php版本中已經(jīng)修復(fù)。在google里搜一下吧,有解釋很詳細的原因。
- 2 回答
- 0 關(guān)注
- 982 瀏覽
添加回答
舉報
0/150
提交
取消