Hi everybody,

I am trying to build a kind of “proxy” script in php that would act as a relay for mp3 streaming. I have a streaming server at home but I don’t have a lot of bandwidth, so that only 3 or 4 persons can listen to my stream, not more. I have a free host with no bandwidth usage limitation. Of course, I can’t install any software on my host so my idea is to create a php script stored on my host that would act as a proxy/relay for my stream.

Instead of listening directly to the streaming source, the listeners open this script in Winamp. In this way, my streaming server would only send ONE occurrence of the stream to my host. If 20 people are actually listening, the 20 instances of this stream would be sent by my HOST, NOT my streaming server. In other words, I would like my script to be able to listen only one time to the streaming source and redistribute to several listeners. This solution would allow me to reach more people because I would use my host’s bandwidth instead of mine…

I used two little scripts that use fsockopen and fopen. So HERE IS THE PROBLEM with both of these scripts. When 2 or more listeners run the script, there are 2 or more connections to my streaming server. How can I change my script so that when 2 or more listeners open it, there is only ONE connection to my streaming server? In other words, I would like the script to download only one time the stream and then redistribute it to the listeners…

Thanks in advance for ANY help!

Macsym

//SCRIPT 1:
<?php
$streamname = "65.86.127.128"; //The streaming server’s IP
$port = "8000"; //The streaming server’s port
$path = "/stream.mp3"; //The path of the stream
$sock = fsockopen($streamname,$port);
fputs($sock, "GET $path HTTP/1.1\n");
fputs($sock, "Connection: close\n\n");
fpassthru($sock);
?>

//SCRIPT 2
<?php
$streamname = "http://65.86.127.128"; //The streaming server’s address
$port = "8000"; //The streaming server’s port
$path = "stream.mp3"; //The path of the stream
$fpr = fopen("$streamname:$port/$path","rb"); //open the stream
$fpw = fopen("$path","wb");

// Loop until there's some data
while ($bytes = fread($fpr, 2048)) {
print $bytes;
fwrite ($fpw, $bytes); // Writes data to a local file
}
?>

    Write a Reply...