簡體   English   中英

php file_get_contents在服務器上不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM