<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Marcus Povey &#187; cron</title>
	<atom:link href="http://www.marcus-povey.co.uk/tag/cron/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcus-povey.co.uk</link>
	<description>Making the world a better place, one byte at a time...</description>
	<lastBuildDate>Fri, 16 Jul 2010 09:00:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<atom:link rel='hub' href='http://www.marcus-povey.co.uk/?pushpress=hub'/>
		<item>
		<title>Its a question of time</title>
		<link>http://www.marcus-povey.co.uk/2008/10/27/its-a-question-of-time/</link>
		<comments>http://www.marcus-povey.co.uk/2008/10/27/its-a-question-of-time/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 18:52:01 +0000</pubDate>
		<dc:creator>Marcus Povey</dc:creator>
				<category><![CDATA[elgg]]></category>
		<category><![CDATA[#ue]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.marcus-povey.co.uk/?p=107</guid>
		<description><![CDATA[Sometimes things need to be done without user interaction &#8211; 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 &#8211; an example [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes things need to be done without user interaction &#8211; for example, database optimisation or log rotation.</p>
<p>For this, Elgg has a cron endpoint.</p>
<p>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 &#8211; an example is given file is included and called <code>crontab.example</code>.</p>
<p>The crontab calls simplified yet powerful cron endpoint &#8211; <code>http://yoursite/pg/cron/<strong>PERIOD</strong></code>, where <strong>PERIOD</strong> is one of the following:</p>
<ul>
<li><strong>reboot</strong> &#8211; Execute on system reboot</li>
<li><strong>minute</strong> &#8211; Execute every minute</li>
<li><strong>fiveminute</strong> &#8211; Execute every five minutes</li>
<li><strong>fifteenmin</strong> &#8211; Execute every fifteen minutes</li>
<li><strong>halfhour</strong> &#8211; Execute every half hour</li>
<li><strong>hourly</strong> &#8211; Execute once every hour</li>
<li><strong>daily</strong> &#8211; Execute every day</li>
<li><strong>weekly</strong> &#8211; Execute weekly</li>
<li><strong>monthly</strong> &#8211; Execute once a month</li>
<li><strong>yearly</strong> &#8211; Execute every year</li>
</ul>
<p>When these endpoints are triggered by your crontab a plugin hook is triggered. To make use of this, register a plugin hook as follows:</p>
<blockquote><p><code>register_plugin_hook('cron', <strong>PERIOD</strong>, 'my_cron_handler');</code></p></blockquote>
<p>Where PERIOD is one of the key words listed above. Here is some sample code using Cron &#8211; in this case it is taken from the system log rotation module I added to SVN today.</p>
<blockquote><p><code>&lt;?php<br />
/**<br />
* Elgg log rotator.<br />
*<br />
* @package ElggLogRotate<br />
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2<br />
* @author Curverider Ltd<br />
* @copyright Curverider Ltd 2008<br />
* @link http://elgg.com/<br />
*/</code></p>
<p><code>/**<br />
* Initialise the plugin.<br />
*<br />
*/<br />
function logrotate_init()<br />
{<br />
$period = get_plugin_setting('period','logrotate');<br />
switch ($period)<br />
{<br />
case 'weekly':<br />
case 'monthly' :<br />
case 'yearly' :<br />
break;<br />
default: $period = 'monthly';<br />
}</code></p>
<p><code>// Register cron hook<br />
register_plugin_hook('cron', $period, 'logrotate_cron');<br />
}</code></p>
<p><code>/**<br />
* Trigger the log rotation.<br />
*<br />
*/<br />
function logrotate_cron($hook, $entity_type, $returnvalue, $params)<br />
{<br />
$resulttext = elgg_echo("logrotate:logrotated");<br />
if (!archive_log())<br />
$resulttext = elgg_echo("logrotate:lognotrotated");</code></p>
<p><code>return $returnvalue . $resulttext;<br />
}<br />
</code><br />
<code>// Initialise plugin<br />
register_elgg_event_handler('init','system','logrotate_init');<br />
?&gt;</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.marcus-povey.co.uk/2008/10/27/its-a-question-of-time/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
