Code: Select all
<?php
$sc_host="192.168.0.1";
$sc_port=8000;
//infinite time limit
set_time_limit(0);
//keeping going even if user aborts(using the STOP button for example)
ignore_user_abort();
//register the function 'byebye' to be called when the app is closed
register_shutdown_function("byebye");
function byebye() {
$shutdown_flag=1;
@fclose($sp);
}
//open connection
$sp = @fsockopen("racmpc", 8000, $errno, $errstr, 30);
if (!$sp) exit("Could not connect to SHOUTcast server.\n");
set_socket_blocking($sp,false);
//Send valid headers
fwrite($sp,"GET / HTTP/1.0\nUser-Agent:SHOUTcast PHP Proxy 0.1\nicy-metadata:1\n\n");
//A little chitchatting
for ($i=0; $i<120; $i++) {
if (feof($sp)) break;
$str.=fread($sp,4096);
usleep(200000);
if (strpos($str,"\r\n\r\n")) break;
}
$head=substr($str,0,strpos($str,"\r\n\r\n"));
$head=eregi_replace("ICY 200 OK\r\n","",$head);
header($head);
flush(); //toilet?
echo substr($str,strpos($str,"\r\n\r\n")+4);
flush();
//Echo the received data
while(!$shutdown_flag) {
$buf=fread($sp,4096);
if (feof($sp)) $shutdown_flag=1;
echo $buf;
flush();
usleep(75000);
}
?>