[英]php file_get_contents not working on server
使用file_get_contents
時出現問題
我需要從網址獲取內容
$header=array();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>implode('\r\n',$header),
'proxy' => 'proxy_address',
'request_fulluri' => True
)
);
$context = stream_context_create($opts);
$file = file_get_contents($url, false, $context);
echo $file;
錯誤消息顯示: file_get_contents(my url) [function.file-get-contents]: failed to open stream: Connection timed out
我嘗試了curl
請求,但得到了相同的響應。 我怎么解決這個問題?
嘗試將超時設置添加到您的選擇:
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>implode('\r\n',$header),
'proxy' => 'proxy_address',
'request_fulluri' => True
),
'timeout' => 60
);
本示例將連接超時設置為60秒
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.