PHP映像清除超过了最大执行时间

时间:2015-03-16 13:41:46

标签: php curl

我正在清理LAMP堆栈上的旧PHP应用程序。 一切似乎都正常,但Request-library中的清除功能每次都会超时。代码接收图像URI。

我在30秒后收到超时错误,如下所示: Fatal error: Maximum execution time of 30 seconds exceeded in /<pathToFolder>/Tools/Request.php on line 133,即行if (curl_multi_select($mh) != -1) {。 图像URI没有任何问题。我还尝试将执行时间最多延长到360秒,但它仍然失败。无限循环,也许?如果是这样,为什么?

有人有任何想法吗?

public static function purge($uri = '') {
    if ($uri == '') {
        throw new Exception('Uri is not set');
    }

    $chVarnish01 = curl_init($uri);
    $chVarnish02 = curl_init($uri);
    $chVarnish03 = curl_init($uri);

    curl_setopt_array($chVarnish01, array(CURLOPT_CUSTOMREQUEST => 'PURGE', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5, CURLOPT_HTTPHEADER => array('varnish: 01')));
    curl_setopt_array($chVarnish02, array(CURLOPT_CUSTOMREQUEST => 'PURGE', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5, CURLOPT_HTTPHEADER => array('varnish: 02')));
    curl_setopt_array($chVarnish03, array(CURLOPT_CUSTOMREQUEST => 'PURGE', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5, CURLOPT_HTTPHEADER => array('varnish: 03')));

    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $chVarnish01);
    curl_multi_add_handle($mh, $chVarnish02);
    curl_multi_add_handle($mh, $chVarnish03);

    $active = null;
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);

    while ($active && $mrc == CURLM_OK) {
        if (curl_multi_select($mh) != -1) {
            do {
                $mrc = curl_multi_exec($mh, $active);
            } while ($mrc == CURLM_CALL_MULTI_PERFORM);
        }
    }

    curl_multi_remove_handle($mh, $chVarnish01);
    curl_multi_remove_handle($mh, $chVarnish02);
    curl_multi_remove_handle($mh, $chVarnish03);
    curl_multi_close($mh);

    return true;
}

0 个答案:

没有答案