2011-01-24 22:02:53 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2011-06-14 15:08:03 +02:00
|
|
|
* Name: Poor Man Cron
|
|
|
|
* Description: Execute updates on pageviews, without the need of commandline php
|
|
|
|
* Version: 1.2
|
|
|
|
* Author: Fabio Comuni <http://kirgroup.com/profile/fabrix>
|
2011-01-24 22:02:53 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
function poormancron_install() {
|
2011-01-28 14:04:40 +01:00
|
|
|
register_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
|
|
|
|
register_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
|
2011-01-24 22:02:53 +01:00
|
|
|
logger("installed poormancron");
|
|
|
|
}
|
|
|
|
|
|
|
|
function poormancron_uninstall() {
|
2011-01-28 14:04:40 +01:00
|
|
|
unregister_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
|
|
|
|
unregister_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
|
|
|
|
logger("removed poormancron");
|
2011-01-24 22:02:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-06-18 08:29:59 +02:00
|
|
|
function poormancron_hook(&$a,&$b) {
|
2011-01-24 22:02:53 +01:00
|
|
|
$now = time();
|
|
|
|
$lastupdate = get_config('poormancron', 'lastupdate');
|
|
|
|
|
|
|
|
// 300 secs, 5 mins
|
|
|
|
if (!$lastupdate || ($now-$lastupdate)>300) {
|
|
|
|
set_config('poormancron','lastupdate', $now);
|
2011-02-24 00:16:12 +01:00
|
|
|
proc_run('php',"include/poller.php");
|
2011-01-24 22:02:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-18 08:29:59 +02:00
|
|
|
function poormancron_procrun(&$a, $argv) {
|
2011-01-28 14:04:40 +01:00
|
|
|
logger("poormancron procrun ".implode(", ",$argv));
|
|
|
|
array_shift($argv);
|
2011-01-24 22:02:53 +01:00
|
|
|
$argc = count($argv);
|
2011-01-28 14:04:40 +01:00
|
|
|
logger("poormancron procrun require_once ".basename($argv[0]));
|
|
|
|
require_once(basename($argv[0]));
|
|
|
|
$funcname=str_replace(".php", "", basename($argv[0]))."_run";
|
|
|
|
|
|
|
|
$funcname($argv, $argc);
|
2011-01-24 22:02:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|