【问题标题】:php curl execution time limitationphp curl执行时间限制
【发布时间】:2018-08-26 17:45:02
【问题描述】:

在使用 PHP 时,我从我的 mysql 数据库中获取图像链接,并将它们回显出来。有600个左右,但是跑了100个左右就停止了。这不是逻辑错误,似乎有一个设置阻止了 php 继续 curl。请告知我应该扩展哪个设置以允许更长的 CURL 谢谢!

这是我现在使用的:

function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_BINARYTRANSFER, true);
$data = curl_exec($ch);
return $data;
}

$htmlaa = file_get_contents_curl($getimagefrom);
$docaa = new DOMDocument();
@$docaa->loadHTML($htmlaa);

同样,它工作得很好,但在运行大约 3 分钟后一直停止。

【问题讨论】:

    标签: php curl settings


    【解决方案1】:

    你可以像这样设置 curl 超时:

    curl_setopt($ch, CURLOPT_TIMEOUT, 1000); //seconds to live

    由于有多种因素会影响执行时间,您还应该检查这两个:

    http://php.net/manual/en/function.set-time-limit.php

    http://php.net/manual/en/info.configuration.php#ini.max-execution-time

    另外请注意,CURLOPT_TIMEOUT 定义了任何 cURL 函数允许执行的时间量。您还应该查看CURLOPT_CONNECTTIMEOUT 选项。

    【讨论】:

    • 我添加了 set_time_limit(0);到文档顶部,但每次仍然在同一点停止。 :(
    • set_time_limit 似乎不是这里的问题。您是否调查了其他超时选项?
    • 我把 curl_setopt($ch, CURLOPT_TIMEOUT, 2000000); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200000);还是不行:(
    • 请帮助我不知道该怎么办
    猜你喜欢
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2011-05-28
    相关资源
    最近更新 更多