All posts by Gregory Cornelius

Subversion, Vendor Branches, and svn_load_dirs.pl

Yesterday, I started work on a project to upgrade the BU CMS to version 3.1.x of WordPress. We follow the vendor branch setup for handling vendor drops as suggested in the Subversion book. Unfortunately, Mac OS X Snow Leopard (10.6.6) does not ship with the additional subversion tools installed, specifically svn_load_dirs.pl. After doing a bit of hunting, I came across a support document for Drupal that pointed me in the right direction.

1. Download the source code for svn_load_dirs.

svn co http://svn.apache.org/repos/asf/subversion/tags/1.6.6/contrib/client-side/svn_load_dirs svn_load_dirs

2. Move svn_load_dirs.pl.in to a bin directory and rename to svn_load_dirs.pl.

mv svn_load_dirs/svn_load_dirs.pl.in ~/bin/svn_load_dirs.pl

3. Because we will not be building subversion from source, we need to edit the script and replace

my $svn = '@SVN_BINDIR@/svn';

with

 my $svn = '/usr/bin/svn';

Using cron to Trigger wp-cron.php

WordPress was designed to run in various hosting environments without additional configuration through targeting the lowest common denominator — shared Linux hosting running php4. Since most hosting companies do not provide support for cron and configuring cron can be imposing to the average user, WordPress includes its own version of “cron” for scheduling tasks, which relies on a visitor request to trigger the execution of wp-cron.php.  This approach in essence occasionally hijacks a request for content to execute scheduled tasks, which is less than ideal and does not offer much in the way of control to the sysadmin.

For the more experienced sysadmin/developer that uses more sophisticated hosting (VPS, dedicated server, or even shared hosting with cron support) there is another option: using cron to execute wp-cron.php. First, wp-cron needs to be disabled in the configuration section of wp-config.php.

define('DISABLE_WP_CRON', true);

Then, simply request wp-cron.php directly using cron. For more information on cron, the Wikipedia article is a good starting point.

To edit a user’s crontab, log into the server via ssh and issue the following:

$> crontab -e

If you don’t use ssh often, you may also need to set the $EDITOR environment variable to an editor that you are comfortable using (e.g. vim, emacs, nano, pico, etc…).

There are two different approaches that can be used to execute wp-cron.php.

1. Use wget or curl to issue a HTTP request for wp-cron.php

*/30 * * * * wget http://example.com/wp-cron.php?doing_wp_cron > /dev/null 2>&1

2. Write a small wrapper script to setup the environment and execute wp-cron.php directly.

*/30 * * * * /usr/bin/php /var/cron-scripts/run-wp-cron.php /dev/null 2>&1
<?php
chdir('/var/www'); // WordPress install DocumentRoot
include('wp-cron.php');
?>

In both examples, ‘/dev/null 2>&1’ is used to send both stdout and stderr to /dev/null which discards any output and errors. By default, cron will send an email to the email address defined for the user.