-
Notifications
You must be signed in to change notification settings - Fork 90
Description
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.