Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl_multi: Unable to get error code #3942

Open
ichaoX opened this issue Oct 25, 2024 · 5 comments
Open

curl_multi: Unable to get error code #3942

ichaoX opened this issue Oct 25, 2024 · 5 comments
Labels
bug Documentation contains incorrect information Extension: curl

Comments

@ichaoX
Copy link

ichaoX commented Oct 25, 2024

Description

The following code:

<?php

$ch = curl_init("http://127.0.0.1:12345");

$mh = curl_multi_init();

curl_multi_add_handle($mh, $ch);

do {
    curl_multi_exec($mh, $running);
    curl_multi_select($mh);
} while ($running > 0);

var_dump(curl_errno($ch), curl_multi_errno($mh));

curl_multi_remove_handle($mh, $ch);


curl_exec($ch);

var_dump(curl_errno($ch), curl_error($ch));

Resulted in this output:

int(0)
int(0)
int(7)
string(81) "Failed to connect to 127.0.0.1 port 12345 after 0 ms: Could not connect to server"

But I expected this output instead:

int(7)
int(7) // I'm not sure.
int(7)
string(81) "Failed to connect to 127.0.0.1 port 12345 after 0 ms: Could not connect to server"

PHP Version

PHP 8.2.23

Operating System

No response

@ichaoX ichaoX added bug Documentation contains incorrect information Status: Needs Triage labels Oct 25, 2024
@cmb69
Copy link
Member

cmb69 commented Oct 27, 2024

I think this works as expected. curl_multi_errno() reports errors regarding the multi handle itself; errors for individual handles which have been added to the multi handle are not propagated. @TimWolla, am I correct? If so, that might need a bit of clarification in the docs.

Anyway, use curl_multi_info_read() to get information about erros on individual handles. See https://www.php.net/manual/en/function.curl-multi-exec.php for a full fledged example.

@TimWolla
Copy link
Member

I think this works as expected. curl_multi_errno() reports errors regarding the multi handle itself; errors for individual handles which have been added to the multi handle are not propagated

Yes. The errno is only filled by the curl_multi_* functions. For curl_multi_exec(), which uses curl_multi_perform() internally, the curl documentation states:

This function returns errors regarding the whole multi stack. Problems on individual transfers may have occurred even when this function returns CURLM_OK. Use curl_multi_info_read to figure out how individual transfers did.

@cmb69 cmb69 transferred this issue from php/php-src Oct 27, 2024
@ichaoX
Copy link
Author

ichaoX commented Oct 27, 2024

Thank you for your explanation. It seems that the doc-en examples were recently updated.

What I was missing was curl_multi_info_read(); adding it allows me to get the error code.

while (curl_multi_info_read($mh) !== false);

var_dump(curl_errno($ch)); // int(7)

Maybe it would be more intuitive to get the error without needing curl_multi_info_read().

@cmb69
Copy link
Member

cmb69 commented Nov 19, 2024

Maybe it would be more intuitive to get the error without needing curl_multi_info_read().

Possibly. But given that ext/curl is a rather thin wrapper over libcurl, I don't see that we go this route.

@cmb69 cmb69 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
@cmb69
Copy link
Member

cmb69 commented Nov 19, 2024

Oh, that has already been moved to doc-en. Reopening.

@cmb69 cmb69 reopened this Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Documentation contains incorrect information Extension: curl
Projects
None yet
Development

No branches or pull requests

4 participants