NYCPHP Meetup

NYPHP.org

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

John Campbell jcampbell1 at gmail.com
Tue Dec 29 10:52:05 EST 2009


David,

I use curl every time I am accessing a remote resource.  I'd fetch the
content with curl, and process it as a string.  Using php's remote
resource is always flaky.  It doesn't work on some installs, may break
with ssl, doesn't support cookies reliably, can't handle http errors,
may or may not follow redirects, etc.  simple_xml_load_file() on a
remote resource is great for article writers because they don't have
to have a bunch of boilerplate curl code in the article, but it is a
mistake for a real application.

Regards,
John Campbell


On Tue, Dec 29, 2009 at 3:53 AM, David Roth <davidalanroth at gmail.com> wrote:
> 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
>
>
> _______________________________________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/Show-Participation
>



More information about the talk mailing list