Drupal Case Study on MCR: FeedAPI, SimplePie Parser, and Cron
Last week at WBR, we re-launched the website for My Chemical Romance. The site’s built on Drupal 6.x and showcases blogs, photos, and tweets directly from the band members.
To aggregate the Twitter feed, we used the FeedAPI module and associated SimplePie parser. Cron runs every 10 minutes to ensure the content stays fresh.
We hit a few bumps getting this all to work.
Feeds rarely updating
Initially, the feeds were scarcely refreshing. The problem was caused by SimplePie doing its own feed caching, with FeedAPI blissfully unaware. To fix this, I wrote a simple patch for parser_simplepie.module (under review as of this writing): http://drupal.org/node/341410
Cron not refreshing feeds
Cron, when invoked from a command-line PHP script, was failing to refresh the feeds. The cause was a default PHP setting of max_execution_time = 0.
FeedAPI uses max_execution_time to calculate its allowed time during a cron run. This value is always set when invoking PHP through the web, but it needs to be explicitly defined in any command line PHP script. This is solved with the following line of code:
ini_set('max_execution_time', 300); // Set to 5 minutes
Cron refresh rate set too high
FeedAPI sets a default cron refresh rate value of 1800 seconds. This prevents cron from refreshing the feeds twice within 30 minutes. For us this was too high (cron runs every 10 minutes). Lowering this to a more reasonable setting did the trick.
feedapi.module (lines 14-15):
// Minimum time that must elapse before a feed can be refreshed again on cron.
define('FEEDAPI_CRON_MIN_REFRESH_TIME', 300);
Everything is now running smoothly!
Tagged cron, drupal, feed, my chemical romance, wbr







