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);Jbrevel