You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using curl_setopt_array to set CURLOPT_RETURNTRANSFER it returns the result and bool.
I was able to fix this by adding curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
bool(true)
But I expected this output instead:
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
Not sure what all I can tell you, other than this problem doesn't make sense.
What does var_dump($options) show? Are you sure the script (the entire file) is exactly as you've posted, with the output exactly as you've posted, and using exactly PHP 8.1.6 and/or 8.1.12? And it does so when you run php -n file.php, which guarantees there's no custom configuration being loaded like extensions or an auto_prepend_file?
@0xearl Can you run the following code with the configuration from the beginning? We should see what is the actual version of the curl, which features are compiled in, if setopt was even successful and eventual error messages.
reading https://www.php.net/manual/en/function.curl-setopt-array.php
it seems like curl_setopt_array is failing to set CURLOPT_TCP_FASTOPEN => true,
and is returning false hence the next curl options are not being set.
I'm not sure as to why curl_setopt_array is failing to set CURLOPT_TCP_FASTOPEN
it didn't even error out @KapitanOczywisty even with var_dump($res, curl_error($ch));
Indeed. That is because curl_error() is implemented via CURLOPT_ERRORBUFFER and as such does not apply to curl_easy_setopt() (i.e. when setting options). That needs to be clarified in the documentation.
You can, however, use curl_errno() (and curl_strerror()):
Activity
damianwadley commentedon Dec 13, 2022
curl_setopt_arrayis equivalent to a foreach loop that callscurl_setopt. There is something else responsible for the problems you're seeing...0xearl commentedon Dec 13, 2022
I'm honestly confused myself, that's the whole code.
damianwadley commentedon Dec 13, 2022
Not sure what all I can tell you, other than this problem doesn't make sense.
What does
var_dump($options)show? Are you sure the script (the entire file) is exactly as you've posted, with the output exactly as you've posted, and using exactly PHP 8.1.6 and/or 8.1.12? And it does so when you runphp -n file.php, which guarantees there's no custom configuration being loaded like extensions or an auto_prepend_file?0xearl commentedon Dec 13, 2022
Running
php -n file.phpreturnsFatal error: Uncaught Error: Call to undefined function curl_init()var_dump($options)showsYes I have tested both 8.1.6 and 8.1.12
damianwadley commentedon Dec 13, 2022
Ah, right, yeah -n will totally disable ext/curl as well. Ahem.
So what I meant was
php -n -d extension=curl file.php.0xearl commentedon Dec 14, 2022
running

php -n -d extension=curl file.phpreturnsbool(false)KapitanOczywisty commentedon Dec 14, 2022
@0xearl Can you run the following code with the configuration from the beginning? We should see what is the actual version of the curl, which features are compiled in, if setopt was even successful and eventual error messages.
0xearl commentedon Dec 14, 2022
@KapitanOczywisty running your code returns
reading https://www.php.net/manual/en/function.curl-setopt-array.php
it seems like curl_setopt_array is failing to set
CURLOPT_TCP_FASTOPEN => true,and is returning
falsehence the next curl options are not being set.I'm not sure as to why curl_setopt_array is failing to set
CURLOPT_TCP_FASTOPENKapitanOczywisty commentedon Dec 14, 2022
Seems like it's not supported on windows: https://curl.se/libcurl/c/CURLOPT_TCP_FASTOPEN.html
0xearl commentedon Dec 14, 2022
I see, thanks @KapitanOczywisty
KapitanOczywisty commentedon Dec 14, 2022
I think there should be a warning when
curl_setopt_arrayis failing on the libcurl side. TBH it's too easy to miss such error.0xearl commentedon Dec 14, 2022
it didn't even error out @KapitanOczywisty even with
var_dump($res, curl_error($ch));cmb69 commentedon Dec 14, 2022
Indeed. That is because
curl_error()is implemented viaCURLOPT_ERRORBUFFERand as such does not apply tocurl_easy_setopt()(i.e. when setting options). That needs to be clarified in the documentation.You can, however, use
curl_errno()(andcurl_strerror()):outputs:
I agree that this might be a good idea, but given the potential BC break, I don't think that we should see this as bug fix, but rather as a feature.
[-]curl_setopt_array doesn't apply CURLOPT_RETURNTRANSFER.[/-][+]curl_setopt(_array) should warn on errors[/+]