]> git.mxchange.org Git - friendica-addons.git/blob - poormancron/poormancron.php
Twitter: The sync process is split into several short processes
[friendica-addons.git] / poormancron / poormancron.php
1 <?php
2 /**
3  * Name: Poor Man Cron
4  * Description: Execute updates on pageviews, without the need of commandline php - only for use in total desperation as page loads will take forever
5  * Version: 1.2
6  * Author: Fabio Comuni <http://kirgroup.com/profile/fabrix>
7  */
8
9 function poormancron_install() {
10         // check for command line php
11         $a = get_app();
12         $ex = Array();
13         $ex[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
14         $ex[1] = dirname(dirname(dirname(__file__)))."/testargs.php";
15         $ex[2] = "test";
16         $out = exec(implode(" ", $ex));
17         if ($out==="test") {
18                 set_config('poormancron','usecli',1);
19                 logger("poormancron will use cli php");
20         } else {
21                 set_config('poormancron','usecli',0);
22                 logger("poormancron will NOT use cli php");
23         }
24         
25         register_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
26         register_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
27         logger("installed poormancron");
28 }
29
30 function poormancron_uninstall() {
31         unregister_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
32         unregister_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
33         logger("removed poormancron");
34 }
35
36
37
38 function poormancron_hook(&$a,&$b) {
39     $now = time();
40     $lastupdate = get_config('poormancron', 'lastupdate');
41
42     // 300 secs, 5 mins
43     if (!$lastupdate || ($now-$lastupdate)>300) {
44         set_config('poormancron','lastupdate', $now);
45         proc_run('php',"include/poller.php");
46     }
47 }
48
49 function poormancron_procrun(&$a, &$arr) {
50         if (get_config('poormancron','usecli')==1) return;
51         $argv = $arr['args'];
52         $arr['run_cmd'] = false;
53         logger("poormancron procrun ".implode(", ",$argv));
54         array_shift($argv);
55         $argc = count($argv);
56         logger("poormancron procrun require_once ".basename($argv[0]));
57         require_once(basename($argv[0]));
58         $funcname=str_replace(".php", "", basename($argv[0]))."_run";
59   
60         $funcname($argv, $argc);
61 }
62
63
64 ?>