I need to somehow restream the Shoutcast/Icecast stream using the PHP.
Why?
Because Shoutcast/Icecast streams are non https. And it's sent through not 80 and 443 port, but some different strange ports. And I need the https links on normal/standard ports like 80 or 443. This is the biggest reason, although there are some more but less important I think.
These links are like http://hostname.com:5921/stream
, and I need links like https://hostname.com/stream?user=x
instead.
I made deep research and did not found much.
I found things like:
https://stackoverflow.com/questions/7998773/is-it-possible-to-restream-an-internet-radio-using-php-php-guru-needed
https://www.svnlabs.com/blogs/radio-icecast-shoutcast-php-proxy-to-re-stream-radio-stream-on-https/
https://stackoverflow.com/questions/36306457/read-mp3-stream-and-echo-back-to-client-in-php
The best code I have collected for now from all resources and my own tries is:
$link = 'http://shoutStreame.streamland.com/proxy/radioGame?mp=/1'; //example link to a Shoutcast stream (not working, only example)
ob_start();
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-Disposition: attachment; filename="stream.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
$handle = fopen($link, 'r');
while (($data = fread($handle, 1024))) {
echo $data;
ob_flush();
flush();
}
And this code doesn't seems to be... good? excellent?
I just feel like I am doing it wrong way with this code, and it's not efficent and may lead to problems.
My main concerns are:
- efficency, especially under many requests
- legal problems? are there any real problems when doing things this way? restreaming using php?
- crash problems? like crash of the whole php, nginx or even machine?
- losing the connection, like this php script will keep dying after a while or something
And there could be maybe more.
It is really hard for me to find any more resources, data and information regarding this particular topic of restreaming the audio stream using the PHP.
For now I do not really know what to do. I am just researching and thinking but as I said, it is really hard to find something more about this topic. And this is the only code I have for now and I do not know if it is good to use it... :)