Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在有限的时间内执行php文件\u获取\u内容并退出_Php_Timeout - Fatal编程技术网

在有限的时间内执行php文件\u获取\u内容并退出

在有限的时间内执行php文件\u获取\u内容并退出,php,timeout,Php,Timeout,是否可以运行php文件获取内容最多25秒,然后停止接收并继续?目标是捕获超时错误 这不会解决问题,因为它只会延长时间并最终导致致命错误 $opts = array('http' => array('method' => 'GET', 'timeout' => 120)); $context = stream_context_create($opts); $html = @file_get_contents($crLink, false, $context); 您可以设置p

是否可以运行php文件获取内容最多25秒,然后停止接收并继续?目标是捕获超时错误

这不会解决问题,因为它只会延长时间并最终导致致命错误

$opts = array('http' => array('method'  => 'GET', 'timeout' => 120));
$context  = stream_context_create($opts);
$html = @file_get_contents($crLink, false, $context);

您可以设置php的
max\u execution\u time
。无论是从php配置还是使用
ini\u set
@Jigar运行时-延长非响应get的时间,都会导致致命错误。确定。不知道
文件\u获取\u内容
,但您可以使用
curl
并尝试设置选项。@Jigar-测试curl。但有可能将目标归档吗?“捕获超时错误”您所说的超时错误是什么意思?我怀疑他们会破例。您可以从标题中获取
内容长度
,并检查是否已获取所有内容,否则这是一个错误。