How to know which URL failed in curl_multi_exec?
Asked Answered
F

1

6

I wrote a class to make it easier to use multi cURL requests I want to log errors when I get a 404 error or any other error. I already have CURLOPT_FAILONERROR set to true.

I'm currently using curl_multi_info_read().

and this is my code:

$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);
        }
    }

The result on error is an array like this:

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 ?
        )

So how can I get the URL where the error happened ? this only gives me the handle resource ID

and thanks in advance.

Finstad answered 29/9, 2012 at 14:51 Comment(0)
J
9

Depending on what you actually need, you can pass this handle to either curl_error or curl_errno function to check for errors, and you can use curl_getinfo to extract the URL from that handle:

curl_getinfo($info['handle'], CURLINFO_EFFECTIVE_URL);
Jaffa answered 29/9, 2012 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.