php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62036 CURLOPT_RETURNTRANSFER returns both boolean and response
Submitted: 2012-05-15 11:18 UTC Modified: 2013-02-18 00:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: ken dot depelchin at gmail dot com Assigned:
Status: No Feedback Package: cURL related
PHP Version: 5.3.13 OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ken dot depelchin at gmail dot com
New email:
PHP Version: OS:

 

 [2012-05-15 11:18 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-20 22:04 UTC] felipe@php.net
-Summary: CURLOPT_RETURNTRANSFER] returns both boolean and response +Summary: CURLOPT_RETURNTRANSFER returns both boolean and response
 [2012-09-22 14:42 UTC] pierrick@php.net
-Status: Open +Status: Feedback
 [2012-09-22 14:42 UTC] pierrick@php.net
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.
 [2013-02-18 00:35 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 21:01:30 2024 UTC