Jan 29

Run Wordpress tasks from real cron job

Category: How-To
Tags: ,,

Hi,

I recently worked with a Wordpress MU installation.  As an ease of deployment and probably because it is largely used on shared hosting which may not offer access to cron jobs, Wordpress default way of processing its scheduled tasks is through front-end and admin page requests.  As a result, everytime a page is requested, the system looks to see if there are jobs to run.  When so a call is performed to execute the tasks.  The asynchronous nature of the call makes it somewhat transparent from the webuser perspective.

Although it works well, I do not feel confident to use this mechanism on a site with a lot of traffic.  After some google searches to find out how it works, I’ve read many stories about hosting companies denying access to wp-cron.php because of bad impact on their server.

I had another issue while using WP-SuperCache.  Since the super cache is super because it prevents loading the whole PHP engine for guest requests.  Unfortunately, no php code execution means no cron execution for super cached pages… Since the cron is responsible of cleaning the super cached files, they are served indefinetly or until a user logs in (logged users do not get super cached files).

So for all the good reason I had, I wanted to run Wordpress cron jobs from a real cron schedule.

Read the How-To on next page

Pages: 1 2

4 comments

4 Comments so far

  1. DS February 9th, 2010 11:17 am

    I implemented this in WPMU 2.9.1.1 with the wp-cron-multi-blog.php script and a /etc/crontab setup and it does not work at all for me. If I manually browse to the script, it reports back as if its working/doing something, but doesn’t appear to actually spawn the cron jobs.

  2. Pascal February 9th, 2010 9:12 pm

    Ok I will double-check it in case I did a copy/paste mistake.

    What are your cron jobs skipped? pre-publishing?

    Pascal.

  3. Helgi Hrafn Halldórsson February 17th, 2010 4:07 am

    Thank you for this post. It helped me alot :P

  4. מרק ק. March 3rd, 2010 10:43 pm

    You can probably make your script more efficient by managing the list of scheduled task, or the blog which has them, in a separate DB table.

    Another enhancement might be to directly call the WP cron task execution API, after calling switch_to_blog for the appropriate blog number.

Leave a comment