Created
April 17, 2011 01:52
-
-
Save gmanley/923672 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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