|
-
Aug 20th, 2011, 07:24 AM
#1
Thread Starter
Fanatic Member
If function fsock open error then echo "Error"
Hi guys,
got a problem, using this script to display the current song being played on my radio station :
Code:
$ip = $row['IP'];
$port = $row['Port'];
}
////////////////////
// END OF CONFIG AREA
//
// DO NOT EDIT BELOW
// UNLESS YOU KNOW WHAT YOU ARE DOING
////////////////////
function getNowPlaying($ip,$port)
{
$open = fsockopen($ip,$port,$errno,$errstr,'.5');
if ($open) {
fputs($open,"GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n");
stream_set_timeout($open,'1');
$read = fread($open,200);
$text = explode(",",$read);
if($text[6] == '' || $text[6] == '</body></html>'){ $msg = ' live stream '; } else { $msg = $text[6]; }
$text = ''.$msg;
} else { return false; }
fclose($open);
return $text;
}
now it works fine, how ever if the stations offline it gives the error :
"Warning: fsockopen() [function.fsockopen]: unable to connect to 64.150.181.14:7028 (Connection timed out) in /home/welovera/public_html/player/index.php on line 468"
Does anyone know how i can make it display "ERROR : STATION OFFLINE" instead of the error above?
Thanks,
Jamie.
-
Aug 20th, 2011, 01:15 PM
#2
Member
Re: If function fsock open error then echo "Error"
Use @fsockopen, it will suppress the error and then your already evaluating $open so change return false; for your error message.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|