Http Streaming Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jbrevel
Forum Newbie
Posts: 1
Joined: Thu Mar 24, 2011 5:15 am

Http Streaming Problem

Post by jbrevel »

Hey guys,

I have an application that connects to the twitter firehose through a third party provider. The twitter stream is delivered through a streaming http method. I am using curl to start the connection but after a while the connection goes down. I have tried putting in a loop but this causes it to create multiple connections which isn't ideal.

Is there a php script which checks if the connection is down and restarts it automatically so we are not missing out on tweets?

Code:

Code: Select all

define('XML_POST_URL', 'https://thirdpartysite/1/track.json');
$filename = '/dev/null';
$ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, "uname:pass");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_URL, XML_POST_URL);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $filename);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $filename);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
        $urlcookie = parse_url($m[1]);
        $urlcookie2 = $urlcookie['path'];
        $opts = array(     
          'http'=>array(            
            'header'=>"Cookie: ".$urlcookie2."\r\n"
          ) 
        ); 
        $context = stream_context_create($opts); 
        //Open stream and start getting data
        $data = fopen('https://thirdpartysite/twitter/feeds/track.json','r' ,false, $context);
Thanks in advance for any help on this,

Jbrevel
Post Reply