Question: I'm planning to record the live tweets on a particular topic. For the same, I'm using the twitter stream API with cURL in PHP.

Here is the code:

```
<?php

$username = "xxxxx";
$password = "xxxxx";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://stream.twitter.com/1/statuses/filter.json?         track=SEARCH_PARAMETER');
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
$jsonOBJ = json_decode ($result);

curl_close($ch);

print_r($jsonOBJ);
?>

```

My problem is, if I set CURLOPT\_RETURNTRANSFER to 0, I can see the tweets on the terminal. But I'm not able to store in the variable $jsonOBJ and print it.

Please Help!

Answer: 
I'm working on the same kind of thing as well :) The problem is that when you do it in terminal, it's a stream, so the connection stays alive until you kill it. (ie the curl\_exec() doesn't finish)

Try looking at CURLOPT\_PROGRESSFUNCTION and CURLOPT\_READFUNCTION. They might give you some hints.
Am just rushing you an answer as leaving for the day. That looks like it should work.

Below is a function I use where I pass it a URL and some XML data and it returns an associative array saying true or false for success and the retuen value as a string.

```
function do_curl($url, $data)
    {
    $ch = curl_init();    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $result = curl_exec ($ch);

    $curl_return=array();

    if (!is_string($result))
        {
        $curl_return['STATUS'] = FALSE;
        $curl_return['ERRMSG'] = curl_error($ch);
        }
    else
        {
        $curl_return['STATUS'] = TRUE;
        $curl_return['RESPONSE'] = $result;
        }
    curl_close($ch); 
    return $curl_return;
    }

```