Sometimes things need to be done without user interaction – for example, database optimisation or log rotation.

For this, Elgg has a cron endpoint.

Cron is a unix tool which executes commands at a specific time of day (other operating systems have similar tools). This keys off a file called a crontab – an example is given file is included and called crontab.example.

The crontab calls simplified yet powerful cron endpoint – http://yoursite/pg/cron/PERIOD, where PERIOD is one of the following:

  • reboot – Execute on system reboot
  • minute – Execute every minute
  • fiveminute – Execute every five minutes
  • fifteenmin – Execute every fifteen minutes
  • halfhour – Execute every half hour
  • hourly – Execute once every hour
  • daily – Execute every day
  • weekly – Execute weekly
  • monthly – Execute once a month
  • yearly – Execute every year

When these endpoints are triggered by your crontab a plugin hook is triggered. To make use of this, register a plugin hook as follows:

register_plugin_hook('cron', PERIOD, 'my_cron_handler');

Where PERIOD is one of the key words listed above. Here is some sample code using Cron – in this case it is taken from the system log rotation module I added to SVN today.

<?php
/**
* Elgg log rotator.
*
* @package ElggLogRotate
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Curverider Ltd
* @copyright Curverider Ltd 2008
* @link http://elgg.com/
*/

/**
* Initialise the plugin.
*
*/
function logrotate_init()
{
$period = get_plugin_setting('period','logrotate');
switch ($period)
{
case 'weekly':
case 'monthly' :
case 'yearly' :
break;
default: $period = 'monthly';
}

// Register cron hook
register_plugin_hook('cron', $period, 'logrotate_cron');
}

/**
* Trigger the log rotation.
*
*/
function logrotate_cron($hook, $entity_type, $returnvalue, $params)
{
$resulttext = elgg_echo("logrotate:logrotated");
if (!archive_log())
$resulttext = elgg_echo("logrotate:lognotrotated");

return $returnvalue . $resulttext;
}

// Initialise plugin
register_elgg_event_handler('init','system','logrotate_init');
?>

It has been a busy week!

We started the week with the ongoing push towards Elgg 1.1, including a number of bug fixes and some translations. The biggest change this week was to move sessions over to a database store – this provides more scalability options as well as making things more secure on shared hosts.

This week also saw the development of the first version of our commercial SMS server that provides both outbound and inbound SMS channels for Elgg installs to hook into. This included a sophisticated client side library which provides simple yet powerful tools for hooking into this feed – the proof of concept was to add SMS functionality to The Wire (so you can now post your Elgg community thoughts on the road!)

More on this to come…

On Thursday, me and Ben were helping out at the OFE stand at the London Linux Expo. We got to meet some very cool people and talk about open standards (such as OpenDD), introduce Elgg, and generally big up FOSS.

I had a good look around the show. The contrast with the Linux side and the Mac side in terms of style was striking.

It depressed me somewhat that the Open Source Village (with a few exceptions like Open Street Map) was pretty much a lesson in what not to do.

It was good to see the projects there, and its great they were given this space. But most people there seemed to be more interested in staring intently at their laptops rather than talking to people or interacting with the other projects.

Contrast this with projects like Ubuntu which had people giving keynotes and wandering around chatting to people.

No prizes to see who is more likely to still be around in a years time…

But, on a positive note, while I was there I discovered that GoDaddy (one of the largest hosts and domain name resellers in the world) are now offering Elgg hosting and support!

And finally, after spending the day working on a commercial build, I spent 15 minutes building a small plugin which enables The Wire to push messages to Twitter. It is now possible to send an SMS to your wire and then out to your twitter – all through some loosely coupled drop-in plugins.

Cool eh?