1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
|
<?php
header("Content-type: audio/mpeg");
$sc_host="xxx.xxx.xxx.xxx";
$sc_port=xxxx;
//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($sc_host, $sc_port, $errno, $errstr, 5);
if (!$sp) exit("Could not connect to SHOUTcast server.\n");
//Send valid headers
fwrite($sp,"GET / HTTP/1.0\nUser-AgentHOUTcast 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=str_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();
}
?> |