vBulletin 5 — running Scheduled Tasks with unix cron

My solution is simple, but it took a couple of hours to figure out how to do that.

The script itself. Remember to put it outside of your document root. I called it cron.php.
<?php

chdir(__DIR__ . '/www/core'); // Specify your full or relative path here

define('THIS_SCRIPT', 'searchindex');
define('VB_AREA', 'Maintenance');
define('SKIP_SESSIONCREATE', 1);
define('VB_ENTRY', true);
define('NOCOOKIES', 1);
require_once('./global.php');
@set_time_limit(0);

vB_Api_Cron::instance('cron')->callNamed('run', ['noshutdownfunc' => true]);

To make sure only one copy of script is running, I’ve used flock. Full cron line looks like that:
*/1 * * * * flock -n /tmp/ahc-cron.lock php /home/sites/example.com/cron.php
Remember to adjust paths. If you have no $PATH set for crontab, you may need to specify full path to flock and php binaries.
Now, you can safely disable “poor man’s cron” with SettingsServer Settings and Optimization OptionsEnable Scheduled Tasks set to No. Watch Next Time column in Scheduled Task Manager to make sure everything works.

Add comment


%d bloggers like this: