Fsockopen error handling, at the moment I get warn

2019-03-05 09:23发布

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条回答
劳资没心,怎么记你
2楼-- · 2019-03-05 10:17

You can supress warnings calling fsockopen

$open_socket = @fsockopen($host,$port,$errno,$errstr,30);
查看更多
登录 后发表回答