Basically, we have this here module that we offer to our users that want to include a feed from elsewhere on their pages. I works great, no sweat. The problem is that whenever users mishandle the feed link on their hands we have to manually remove the module from existence because Zend Feed crashes and burns the entire page just like any fatal error. Normally, one would expect that a code block such as..
try { // Test piece straight off the Zend tutorial
$slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}
.. would BEHAVE if I were to enter 'httn://rss.grrllarrrlll.aarrg/Slashdot/slashdot' and say something along the lines of "404" or "What the shit". No. It dies. It crashes and dies. It crashes and burns and dies, completely ignoring all that happy trycatch methology right there.
So basically, do we have to write our on feedfetch or is there any simple remedy to Zend's slip?
Added log:
exception 'Zend_Http_Client_Adapter_Exception' with message 'Unable to Connect to tcp://www.barglllrragglll:80. Error #10946: ' in /library/Zend/Http/Client/Adapter/Socket.php:148
#0 /library/Zend/Http/Client.php(827): Zend_Http_Client_Adapter_Socket->connect('www.barglllrragglll...', 80, false)
#1 /library/Zend/Feed.php(284): Zend_Http_Client->request()
...... Trace etc ....
Just out of curiosity, did you try catching other kinds of exception ? ie, not only Zend_Feed_Exception
?
Maybe, if there is some kind of 404 error during the "fetching" phase, it throws another exception ? (Because of relying on another component, like Zend_Http_Client
? )
Also, did you check your error_reporting
level, to be sure errors would be reported ? Maybe in some log file somewhere, if display_errors
is Off
?
As a sidenot, and not really an answer to your question, but Zend_Feed
has some drawbacks (like returning different kind of data depending on the feed's format -- RSS vs ATOM, for instance).
Starting with Zend Framework 1.9 (right now, it's only available as a preview or alpha version, so don't using it in production !), there will be a Zend_Feed_Reader
component, which should be more useful when consumming both RSS and ATOM Feeds.
For more informations, see
Edit after you added the log
For Zend_Feed
, there is no problem with the Feed itself, so it doesn't throw a Zend_Feed
-related Exception.
The problem you have here is another one, like wrong URL : it fails getting the data, and not analysing it ; it explains why the exception is not Zend_Feed
-related, but Zend_Http_Client
-related.
You might want to add some other exception-handling-code ; something like this :
try { // Test piece straight off the Zend tutorial
$slashdotRss = Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
} catch (Zend_Http_Client_Exception $e) {
echo "There is something wrong with the URL you provided for the feed";
exit;
} catch (Exception $e) {
echo "There is something wrong, we don't know what...";
exit;
}
This way :