微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 如何知道curl_multi_exec中哪个URL失败?

我编写了一个类,以便更容易使用多个cURL请求,当我收到404错误或任何其他错误时,我想记录错误.
我已经将CURLOPT_FAILONERROR设置为true.

我目前正在使用curl_multi_info_read().

这是我的代码

$active = null;
    do {
        $multi_exec = curl_multi_exec($this->_multi_handle,$active);
    } while ($multi_exec == CURLM_CALL_MULTI_PERFORM);

    while ($active && $multi_exec == CURLM_OK) {
        if (curl_multi_select($this->_multi_handle) != -1) {
            do {
                $multi_exec = curl_multi_exec($this->_multi_handle,$active);
                $info = curl_multi_info_read($this->_multi_handle);
                if ( $info['result'] != 0 ) {
                    $this->_errors[] = $info; // currently storing the whole array
                }
            } while ($multi_exec == CURLM_CALL_MULTI_PERFORM);
        }
    }

错误的结果是这样的数组:

Array
(
    [0] => Array
        (
            [msg] => 1
            [result] => 22 // on success this is 0
            [handle] => Resource id #4 // does this help in finding the url if I have the handle ID ?
        )

那么如何才能获得发生错误的URL?这只给了我句柄资源ID

并提前感谢.

根据您的实际需要,您可以将此句柄传递给 curl_errorcurl_errno函数以检查错误,并且可以使用 curl_getinfo从该句柄中提取URL:
curl_getinfo($info['handle'],CURLINFO_EFFECTIVE_URL);

原文地址:https://www.jb51.cc/php/240239.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐