2 require_once 'Pman.php';
5 * notification script runner
7 * This does not actualy send stuf out, it only starts the NotifySend/{id}
8 * which does the actuall notifcations.
10 * It manages a pool of notifiers.
16 class Pman_Core_Notify extends Pman
19 var $table = 'core_notify';
20 var $target = 'Core/NotifySend';
24 $ff = HTML_FlexyFramework::get();
28 HTML_FlexyFramework::ensureSingle(__FILE__, $this);
37 //DB_DataObject::debugLevel(1);
38 //date_default_timezone_set('UTC');
41 $w = DB_DataObject::factory($this->table);
42 $w->whereAdd('act_when > sent'); // eg.. sent is not valid..
43 $w->whereAdd('act_when < NOW()'); // eg.. not if future..
45 $w->orderBy('act_when ASC'); // oldest first.
46 $w->limit(1000); // we can run 1000 ...
47 $ar = $w->fetchAll('id');
53 if (!$this->poolfree()) {
57 $p = array_shift($ar);
60 while(count($this->pool)) {
71 $tn = tempnam(ini_get('session.save_path'),'stdout') . '.stdout';
72 $descriptorspec = array(
73 0 => array("pipe", 'r'), // stdin is a pipe that the child will read from
74 1 => array("file", $tn, 'w'), // stdout is a pipe that the child will write to
75 2 => array("pipe", "w") // stderr is a file to write to
78 $sn = $_SERVER["SCRIPT_NAME"];
80 $cwd = $sn[0] == '/' ? dirname($sn) : dirname(realpath(getcwd() . $sn)); // same as run on.. (so script should end up being same relatively..)
81 $app = $cwd . '/' . basename($_SERVER["SCRIPT_NAME"]) . ' ' . $this->target . '/'. $id;
82 $cmd = $php . ' ' . $app. ' &';
85 $p = proc_open($cmd, $descriptorspec, $pipes, $cwd );
86 $this->pool[] = array('proc' => $p, 'out' => $tn, 'cmd' => $cmd);
91 foreach($this->pool as $p) {
92 $ar = proc_get_status($p['proc']);
99 echo $p['cmd'] . " : " . file_get_contents($p['out']);
103 if (count($pool) < 10) {