Search code examples
error-handlingfsockopen

Fsockopen error handling, at the moment I get warnings and page stops further content from loading


I have the following code:

$open_socket = fsockopen($host,$port,$errno,$errstr,30);
if(!$open_socket){
    echo "$errstr ($errno)<br />".$nl;
}else{
    fputs($open_socket,$xml);
    while(!feof($open_socket)){
        $line = fgets($open_socket,128);
        $return_xml.= $line;
    }
    fclose($open_socket);
}

but if there is not connection I get the following message:

Warning: fsocket ......

the rest of the page is blank, basically how can I handle this where my page will continue and things will be displayed and just the error message is displayed and not the warning.

Thanks


Solution

  • You can supress warnings calling fsockopen

    $open_socket = @fsockopen($host,$port,$errno,$errstr,30);