]> git.mxchange.org Git - friendica-addons.git/blob - poormancron/poormancron.php
493f0f17a17ae2960d81a3fa2aa9b803d2922ea5
[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  * Status: Unsupported
8  */
9
10 function poormancron_install() {
11         // check for command line php
12         $a = get_app();
13         $ex = Array();
14         $ex[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
15         $ex[1] = dirname(dirname(dirname(__file__)))."/testargs.php";
16         $ex[2] = "test";
17         $out = exec(implode(" ", $ex));
18         if ($out==="test") {
19                 set_config('poormancron','usecli',1);
20                 logger("poormancron will use cli php");
21         } else {
22                 set_config('poormancron','usecli',0);
23                 logger("poormancron will NOT use cli php");
24         }
25         
26         register_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
27         register_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
28         logger("installed poormancron");
29 }
30
31 function poormancron_uninstall() {
32         unregister_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
33         unregister_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
34         logger("removed poormancron");
35 }
36
37
38
39 function poormancron_hook(&$a,&$b) {
40         return; // deactivated
41
42         //$now = time();
43         //$lastupdate = get_config('poormancron', 'lastupdate');
44
45         // 300 secs, 5 mins
46         //if (!$lastupdate || ($now-$lastupdate)>300) {
47         //      set_config('poormancron','lastupdate', $now);
48         //      proc_run('php',"include/poller.php");
49         //}
50 }
51
52 function poormancron_procrun(&$a, &$arr) {
53         return; // deactivated
54
55         if (get_config('poormancron','usecli')==1) return;
56         $argv = $arr['args'];
57         $arr['run_cmd'] = false;
58         logger("poormancron procrun ".implode(", ",$argv));
59         array_shift($argv);
60         $argc = count($argv);
61         logger("poormancron procrun require_once ".basename($argv[0]));
62         require_once(basename($argv[0]));
63         $funcname=str_replace(".php", "", basename($argv[0]))."_run";
64   
65         $funcname($argv, $argc);
66 }
67
68
69 ?>