Fix: SimplePie Feed Randomly Disappearing
I had the distinct pleasure of getting to utilize SimplePie recently for a small project that was requested by a client. What is SimplePie? Here’s their description:
SimplePie is a very fast and easy-to-use feed parser, written in PHP, that puts the ‘simple’ back into ‘really simple syndication
It works well. Very well — when configured properly! Those of us who have notices and PHP errors turned off may run into an issue that is not often talked about (and so the fix is not apparent).
The issue: SimplePie works, but randomly shows blank pages or the fields keep disappearing on your page. Almost as if…it’s not caching. Which is the entire issue!
With PHP errors / notices / warnings on, you’d see a similar message that looks like below:
Warning: ./cache is not writeable. Make sure you’ve set the correct relative or absolute path, and that the location is server-writable. in /var/www/xxxxxxxxxxx/library/SimplePie.php on line 1369
So the issue is either (A) The path to the CACHE folder is wrong (B) Your permissions on the folder are incorrect
If you are having permission issues, then try experimenting with different CHMOD levels: 755, 757, 775, or 777 (which should be fail-safe).
For me, it was the location of the cache folder not being correct. You can actually set this through your PHP file(s) themselves though. For example, the below line will set it to the cache folder in your root directory (i.e. website.com/cache/)
$feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache/');
Hope it helps.