a65cf31908d420474f85dc1db377cd9238fa68f7
[Pman.Core] / Notify.php
1 <?php
2 require_once 'MTrackWeb.php';
3
4 /**
5  * notification script runner
6  *
7  * This does not actualy send stuf out, it only starts the NotifySend/{id}
8  * which does the actuall notifcations.
9  *
10  * It manages a pool of notifiers.
11  * 
12  * 
13  */
14
15 class Pman_Core_Notify extends Pman
16 {
17     
18     function getAuth()
19     {
20         $ff = HTML_FlexyFramework::get();
21         if (!$ff->cli) {
22             die("access denied");
23         }
24         HTML_FlexyFramework::ensureSingle(__FILE__, $this);
25         return true;
26         
27     }
28     
29     var $pool = array();
30     
31     function get()    
32     {
33         //DB_DataObject::debugLevel(1);
34         date_default_timezone_set('UTC');
35         
36         
37         $w = DB_DataObject::factory('core_notify');
38         $w->whereAdd('act_when < sent');
39         $w->orderBy('act_when ASC'); // oldest first.
40         $w->limit(1000); // we can run 1000 ...
41         $ar = $w->fetchAll('id');
42         
43         while (true) {
44             if (empty($ar)) {
45                 break;
46             }
47             if (!$this->poolfree()) {
48                 sleep(10);
49                 continue;
50             }
51             $p = array_shift($ar);
52             $this->run($p);
53         }
54         
55          
56     }
57     
58     function run($id) {
59         $php = 'php';
60         $cwd = realpath(dirname(__FILE__) . '/../../');
61         $app = 'index.php' .'/Core/NotifySend.php '. $id;
62         $cmd = $php . ' ' . $app;
63         $p = proc_open($cmd, $cwd , array());
64         $this->pool[] = $p;
65     }
66     
67     function poolfree() {
68         foreach($this->pool as $p)
69         
70         
71         
72     }
73     
74     
75 }