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
This was working but now it is not. Now $response comes back as true, rather than as the data. However when I remove the setOption line, I get the data.
What appears to be happening is that cURL has issues with the order of setting CURLOPT_RETURNTRANSFER and CURLOPT_WRITEFUNCTION.
Your current code sets CURLOPT_WRITEFUNCTION into the options array in _httpRequest() then adds the default options after in getOptions(). With no explicit setting of CURLOPT_RETURNTRANSFER, this means that CURLOPT_WRITEFUNCTION is set ahead of CURLOPT_RETURNTRANSFER in the array and when calling curl_setopt_array(). What happens now, is that the CURLOPT_WRITEFUNCTION callback anonymous function does not get called. The data is returned correctly in $body.
If CURLOPT_RETURNTRANSFER is explicitly set as in my code, then the order in the array changes, CURLOPT_RETURNTRANSFER is set first and hence set first with curl_setopt_array(). Now the callback function is called and messes up the data.
Why cURL exhibits this behavior I don't know and I haven't tried digging through the code. There is an interesting comment here an=bout using them together: http://php.net/manual/en/function.curl-setopt.php just search.
I don't understand the need for the callback function. I can't work out in what case it might be needed and it now seems to mess with your latest changes. I would suggest that it be completely removed unless I am missing something. That certainly makes my code work.
Of course the other way to "fix" this is to not set CURLOPT_RETURNTRANSFER explicitly.
The text was updated successfully, but these errors were encountered:
Thanks for your request and all the details. I tried to reproduce this behavior and also tried to fix that. So in that way, the order of "defaultOptions" is not changed anymore. The state you got should not come back anymore.
Your latest changes broke my code. I have some idea why.
I was explicitly setting CURLOPT_RETURNTRANSFER to true:
$response = $curl ->setOption(CURLOPT_RETURNTRANSFER, true) ->get($url)
This was working but now it is not. Now $response comes back as true, rather than as the data. However when I remove the setOption line, I get the data.
What appears to be happening is that cURL has issues with the order of setting CURLOPT_RETURNTRANSFER and CURLOPT_WRITEFUNCTION.
Your current code sets CURLOPT_WRITEFUNCTION into the options array in _httpRequest() then adds the default options after in getOptions(). With no explicit setting of CURLOPT_RETURNTRANSFER, this means that CURLOPT_WRITEFUNCTION is set ahead of CURLOPT_RETURNTRANSFER in the array and when calling curl_setopt_array(). What happens now, is that the CURLOPT_WRITEFUNCTION callback anonymous function does not get called. The data is returned correctly in $body.
If CURLOPT_RETURNTRANSFER is explicitly set as in my code, then the order in the array changes, CURLOPT_RETURNTRANSFER is set first and hence set first with curl_setopt_array(). Now the callback function is called and messes up the data.
Why cURL exhibits this behavior I don't know and I haven't tried digging through the code. There is an interesting comment here an=bout using them together: http://php.net/manual/en/function.curl-setopt.php just search.
I don't understand the need for the callback function. I can't work out in what case it might be needed and it now seems to mess with your latest changes. I would suggest that it be completely removed unless I am missing something. That certainly makes my code work.
Of course the other way to "fix" this is to not set CURLOPT_RETURNTRANSFER explicitly.
The text was updated successfully, but these errors were encountered: