NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP error handling with simplexml_load_file questions.

David Roth davidalanroth at gmail.com
Tue Dec 29 03:53:53 EST 2009


I've been following the example for PHP error handling using  
simplexml_load_file as show in this example:

http://www.ibm.com/developerworks/library/x-simplexml.html

To test my PHP code, I put in a bogus URL, which failed and the PHP  
script caught it allowing me to control it in the program.

But when the actual URL's server is down, PHP gives errors about it  
and aborts the script. The error handling isn't caught by this method.  
I had a PHP script running for months without a problem and I guess it  
had just been lucky until recently not to encounter any network  
problems.

The CRON was nice enough to e-mail root errors from the script that it  
complained about:

PHP Warning:  simplexml_load_file(): php_network_getaddresses:  
getaddrinfo failed: Temporary failure in name resolution in  
blahblah.php on line 17
PHP Warning:  simplexml_load_file(http://example.com): failed to open  
stream: Connection timed out in blahblah.php on line 17
PHP Warning:  simplexml_load_file(): I/O warning : failed to load  
external entity "http://example.com" in blahblah.php on line 17

My impression is that the PHP program encountered these errors and  
simply aborted and didn't give my code a chance to execute.

Is the technique in this article wrong? What can be done to make this  
more robust cause networks won't be up and running all the time. Thanks!

David Roth


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20091229/6c54f377/attachment.html>


More information about the talk mailing list