I have a routine to access the webservice of the mails that uses simplexml_load_file, but if for some reason the post office website is out of order or if it takes too long to respond to my site it returns an error, then I would like to handle this error of loading the simplexml_load_file, so that I can present a personalized message to the user, tried in some ways more unsuccessfully, follow my current code:
$url = "http://ws.correios.com.br/calculador/CalcPrecoPrazo.aspx?";
$url .= "nCdEmpresa=" . $cod_administrativo;
$url .= "&sDsSenha=" . $senha;
$url .= "&sCepOrigem=" . $cep_origem;
$url .= "&sCepDestino=" . $cep_destino;
$url .= "&nVlPeso=" . $peso;
$url .= "&nVlLargura=" . $largura;
$url .= "&nVlAltura=" . $altura;
$url .= "&nCdFormato=1";
$url .= "&nVlComprimento=" . $comprimento;
$url .= "&sCdMaoPropria=" . $mao_propria;
$url .= "&nVlValorDeclarado=" . $valor;
$url .= "&sCdAvisoRecebimento=" . $aviso_recebimento;
$url .= "&nCdServico=" . $servico;
$url .= "&nVlDiametro=0";
$url .= "&StrRetorno=xml";
$xml = simplexml_load_file($url);
if ($xml === false || $xml === 0 || $xml === "") {
return '';
}
return $xml->cServico;