curl — php file_get_contents не работает на сервере

У меня проблема при использовании file_get_contents

Мне нужно получить контент с URL

$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 запрос, но получить тот же ответ. Как я могу решить эту проблему?

0

Решение

попробуйте добавить настройку тайм-аута к вашим опциям:

$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>implode('\r\n',$header),
'proxy' => 'proxy_address',
'request_fulluri' => True
),
'timeout' => 60
);

В этом примере время ожидания соединения составляет 60 секунд.

0

Другие решения

Других решений пока нет …