Fsockopen error handling, at the moment I get warn

2019-03-05 09:22发布

问题:

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

回答1:

You can supress warnings calling fsockopen

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