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: 
@Reza Sanaie and others who may find this helpful.

I used the SEARCH TWITTER API and get the live tweets as well. So this could be helpful. 
Here is the code:

```
<?php
$query = "SEARCH_PARAMETER";
$request = "http://search.twitter.com/search.json?q=".urlencode($query);
$response = file_get_contents($request);
$jsonobj = json_decode($response);
 print_r($jsonobj);
?>

```

I also have the MySQL connection setup to push it into the database and this script is added in the crontab to automate the whole process.
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;
    }

```