這篇文章主要介紹了PHP file_get_contents函數(shù)讀取遠(yuǎn)程數(shù)據(jù)超時(shí)的解決方法,本文直接給出解決方法代碼,需要的朋友可以參考下
在網(wǎng)絡(luò)狀況比較差的情況下file_get_contents函數(shù)經(jīng)常讀取遠(yuǎn)程數(shù)據(jù)失敗。
解決辦法如下:
代碼如下:
/*設(shè)置超時(shí)配合失敗之后嘗試多次讀取,效果比原先好很多*/
$url = 'http://www.jb51.net';
$opts = array(
'http'=>array(
'method'=>"
)
);
$context = stream_context_create($opts);
$contents = @file_get_contents($url,false,$context);
?>
| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注