I'm writing a script to display if a shoutcast (streaming mp3) server is on or offline. This is the problem:
Sometimes it would say a server is offline even if it was online (sometimes, depending on the server). I figured it wasn't trying to connect te server for enough time.
I tried this line but it would not keep trying to connect to the server for 15 seconds. it will try for like 1 second and if the server is a little lagged it will say it's offline:
$server1 = @fsockopen($addr, $port, $errno, $errstr, 15);
$errno and $errstr are both blank when I try to echo them.
So I tried this:
$server1 = @fsockopen($addr, $port, $errno, $errstr, 5);
stream_set_timeout($server1, 5);
fclose($server1);
and i get these errors:
Warning: stream_set_timeout(): supplied argument is not a valid stream resource in /home/www.djbrunofacca.com.br/radio.php on line 77
Warning: fclose(): supplied argument is not a valid stream resource in /home/www.djbrunofacca.com.br/radio.php on line 78
My questions are: Why are the $errno and $errstr blank? Why does the error say it's not a valid stream resource? How can I make sure fsockopen() keeps triying to connect for at least 10 sec?
Don't forget we're talking to a connection to a server that is online, but maybe is a little slow.
Thank you in advance