1

Possible Duplicate:
curl_exec printing results when I don't want too

I am having an issue where the function "curl_exec" prints text to the screen. Here is my code:

$ch = curl_init("https://go.urbanairship.com/api/push/");
if ($ch) {
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "***:***"); // omitted
    curl_setopt($ch, CURLOPT_HTTPHEADER, array ("Content-Type: application/json"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["' . $device_token . '"], "aps": {"alert": "Hello! fucker!"}}'); 
    curl_exec($ch);
}

Calling: print_r(curl_getinfo($ch)); after curl_exec($ch); gives.

Array ( [url] => https://go.urbanairship.com/api/push/ 
        [content_type] => application/json; charset=utf-8 
        [http_code] => 200 
        [header_size] => 222 
        [request_size] => 327 
        [filetime] => -1 
        [ssl_verify_result] => 0 
        [redirect_count] => 0 
        [total_time] => 0.111714 
        [namelookup_time] => 0.029124 
        [connect_time] => 0.036017 
        [pretransfer_time] => 0.065684 
        [size_upload] => 0 [size_download] => 4 
        [speed_download] => 35 
        [speed_upload] => 0 
        [download_content_length] => 4 
        [upload_content_length] => 0 
        [starttransfer_time] => 0.111686 
        [redirect_time] => 0 
      )

The request was successful. I just find it strange that it prints null. Any help?

Community
  • 1
  • 1
Collin Price
  • 5,620
  • 3
  • 33
  • 35
  • 1
    Printing to stdout is its quirky default mode of operation. You need [`_RETURNTRANSFER`](http://php.net/manual/en/function.curl-exec.php). – mario Jan 28 '12 at 19:42

1 Answers1

2

Add

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Rohit Chopra
  • 2,791
  • 4
  • 28
  • 33