Bug #62036 [Opn->Fbk]: CURLOPT_RETURNTRANSFER returns both boolean and response
| From: | pierrick@php.net | Date: | Sat, 22 Sep 2012 14:42:48 +0000 |
| Subject: | Bug #62036 [Opn->Fbk]: CURLOPT_RETURNTRANSFER returns both boolean and response | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-173648@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62036&edit=1
ID: 62036
Updated by: pierrick@php.net
Reported by: ken dot depelchin at gmail dot com
Summary: CURLOPT_RETURNTRANSFER returns both boolean and
response
-Status: Open
+Status: Feedback
Type: Bug
Package: cURL related
Operating System: N/A
PHP Version: 5.3.13
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
The script work for me if I do a json_decode of $result. Can you give me the
exact script you're using to get your problem (if it's not this one) but also the
expected and actual result.
Previous Comments:
------------------------------------------------------------------------
[2012-05-15 11:18:33] ken dot depelchin at gmail dot com
Description:
------------
When calling a API and converting the response to an associative array, the returned response can
not be converted because of the extra boolean in the response. Only viewable when exit($response)
The options of the cURL operation are set using the @curl_setopt_array($ch, $array).
When checked for the header, it does not indicate any problem and it outputs the correct content
(with content length)
When dumped the boolean is dumped with the correct response.
Test script:
---------------
// check if curl is available
if(!function_exists('curl_init')) throw new Exception('This method requires cURL
(http://php.net/curl), it seems like the extension isn\'t installed.');
$url = 'http://ws.audioscrobbler.com/2.0/?method=album.getbuylinks&artist=radiohead&album=in%20rainbows&country=united%20kingdom&api_key=b25b959554ed76058ac220b7b2e0a026&format=json';
// set options
// $options[CURLOPT_URL] = (string) $url;
// $options[CURLOPT_USERAGENT] = 'PlonkHTTP '. self::version;
// $options[CURLOPT_FOLLOWLOCATION] = true;
// $options[CURLOPT_RETURNTRANSFER] = true;
// $options[CURLOPT_TIMEOUT] = 20;
// $options[CURLOPT_HEADER] = true;
// init
$curl = @curl_init();
// @curl_setopt_array($curl, $options);
curl_setopt($curl,CURLOPT_URL, (string) $url);
curl_setopt($curl,CURLOPT_USERAGENT,'PlonkHTTP');
curl_setopt($curl,CURLOPT_RETURNTRANSFER, true);
// execute
$response = @curl_exec($curl);
// fetch errors
$errorNumber = @curl_errno($curl);
$errorMessage = @curl_error($curl);
// close
@curl_close($curl);
Expected result:
----------------
The script will result in a decent response on a local webserver. In a production environment, it
gives the extra boolean when outputted.
Actual result:
--------------
http://ws.audioscrobbler.com/2.0/?method=album.getbuylinks&artist=radiohead&album=in%20rainbows&country=united%20kingdom&api_key=b25b959554ed76058ac220b7b2e0a026&format=json
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62036&edit=1