Results 1 to 2 of 2

Thread: If function fsock open error then echo "Error"

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    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.

  2. #2
    Member PBertie's Avatar
    Join Date
    Aug 2011
    Location
    Newcastle Upon Tyne
    Posts
    55

    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
  •  



Click Here to Expand Forum to Full Width