-
Notifications
You must be signed in to change notification settings - Fork 7.9k
curl: exceptions in callbacks do not abort the request #16513
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
Comments
Well, the proper way to cause the tranfer to be aborted, is to return something else than Lines 600 to 604 in 01aeaf2
Frankly, I don't know why we do not signal abort in this case. Even just removing the |
The documentation indeed says:
Would the exception have the priority however or would this result in a |
Our docs are not quite up to date; better check https://curl.se/libcurl/c/CURLOPT_WRITEFUNCTION.html for details. With the following patch: ext/curl/interface.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ext/curl/interface.c b/ext/curl/interface.c
index 677eaa8703..eb1511eb8a 100644
--- a/ext/curl/interface.c
+++ b/ext/curl/interface.c
@@ -601,6 +601,8 @@ static size_t curl_write(char *data, size_t size, size_t nmemb, void *ctx)
_php_curl_verify_handlers(ch, /* reporterror */ true);
/* TODO Check callback returns an int or something castable to int */
length = zval_get_long(&retval);
+ } else if (EG(exception)) {
+ length = -1;
}
zval_ptr_dtor(&argv[0]); the test script outputs:
|
I think that is an adequate resolution of the issue, and would help a lot. Can we expect this to be fixed in the next PHP release? |
Description
A curl request may take time (sometimes an infinite amount of time) to respond. When an exception is thrown in a callback it is properly forwarded to the curl_exec, however in some cases such as server-sent events, the request may never end.
When an exception happens in a callback, the request should be aborted.
The following code:
Resulted in this output:
(then nothing, the script freezes there)
But I expected this output instead:
PHP Version
PHP 8.2.20
Operating System
No response
The text was updated successfully, but these errors were encountered: