Skip to content

Instantly share code, notes, and snippets.

@gmanley
Created April 17, 2011 01:52
Show Gist options
  • Save gmanley/923672 to your computer and use it in GitHub Desktop.
Save gmanley/923672 to your computer and use it in GitHub Desktop.
<?php
// Pull from the db the list of channel names
$channels = array('music-for-japan-2011', '6819043', 'chelupa');
function live_channels($channels)
{
$live_channels = array();
$channels_string = implode(';', $channels);
$url = 'http://api.ustream.tv/php/channel/'.$channels_string.'/getinfo';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$response = curl_exec($ch);
curl_close($ch);
$resultsArray = unserialize($response);
foreach ($resultsArray['results'] as $result) {
if($result['result']['status'] == 'live') {
$live_channels[] = $result['uid'];
//print_r($result);
}
}
return $live_channels;
}
while (1) {
foreach (live_channels($channels) as $live_channel) {
echo "$live_channel is live!\n";
// Mysql query here? set a boolean value on the channels that are live
}
sleep(20); // Make the request only every 20sec
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment