Notify.php
[Pman.Core] / Notify.php
index a819c6a..902b7a4 100644 (file)
@@ -85,9 +85,18 @@ class Pman_Core_Notify extends Pman
             'max' => 100,
         ),
     );
-    
+    /**
+     * @var $nice_level Unix 'nice' level to stop it jamming server up.
+     */
     var $nice_level = false;
+    /**
+     * @var $max_pool_size maximum runners to start at once.
+     */
     var $max_pool_size = 10;
+    /**
+     * @var $max_to_domain maximum connections to make to a single domain
+     */
+    var $max_to_domain = 10;
     
     var $table = 'core_notify';
     var $target = 'Core/NotifySend';
@@ -149,7 +158,7 @@ class Pman_Core_Notify extends Pman
             
         }
      
-        //DB_DataObject::debugLevel(1);
+        DB_DataObject::debugLevel(1);
         $w = DB_DataObject::factory($this->table);
         
         if (!$showold) {
@@ -157,7 +166,7 @@ class Pman_Core_Notify extends Pman
             // standard
             
             //$w->whereAdd('act_when > sent'); // eg.. sent is not valid..
-            $w->whereAdd("sent < '1970-01-01'"); // eg.. sent is not valid..
+            $w->whereAdd("sent < '1970-01-01' OR sent IS NULL"); // eg.. sent is not valid..
             
             $w->whereAdd('act_start > NOW() - INTERVAL 14 DAY'); // ignore the ones stuck in the queue
             if (!$this->force) {
@@ -222,7 +231,7 @@ class Pman_Core_Notify extends Pman
                 sleep(3);
                 continue;
             }
-            if ($this->poolHasDomain($p->person_id_email)) {
+            if ($this->poolHasDomain($p->person_id_email) > $this->max_to_domain) {
                 
                 if ($pushed === false) {
                     // we only try once to requeue..
@@ -248,11 +257,10 @@ class Pman_Core_Notify extends Pman
             $this->poolfree();
              sleep(3);
         }
-        
-        
+         
         foreach($requeue as $p) {
             $pp = clone($p);
-            $p->event_when = strtotime($p->event_when .  ' + 1 MINUTE');
+            $p->act_when = $p->sqlValue('NOW + INTERVAL 1 MINUTE');
             $p->update($pp);
             
         }
@@ -272,13 +280,21 @@ class Pman_Core_Notify extends Pman
         }
         
         // phpinfo();exit;
-        $tn = tempnam(ini_get('session.save_path'),'stdout') . '.stdout';
+        $tnx = tempnam(ini_get('session.save_path'),'stdout');
+        unlink($tnx);
+        $tn =  $tnx . '.stdout';
         $descriptorspec = array(
             0 => array("pipe", 'r'),  // stdin is a pipe that the child will read from
             1 => array("file", $tn, 'w'),  // stdout is a pipe that the child will write to
             2 => array("pipe", "w") // stderr is a file to write to
          );
-        $php = $_SERVER["_"];
+        
+        static $php = false;
+        if (!$php) {
+            require_once 'System.php';
+            $php = System::which('php');
+        }
+        
         $sn =  $_SERVER["SCRIPT_NAME"];
         
         $cwd = $sn[0] == '/' ? dirname($sn) : dirname(realpath(getcwd() . '/'. $sn)); // same as run on.. (so script should end up being same relatively..)
@@ -400,14 +416,15 @@ class Pman_Core_Notify extends Pman
      */
     function poolHasDomain($email)
     {
+        $ret = 0;
         $dom = strtolower(array_pop(explode('@',$email)));
         foreach($this->pool as $p) {
             $mdom = strtolower(array_pop(explode('@',$p['email'])));
             if ($mdom == $dom) {
-                return true;
+                $ret++;
             }
         }
-        return false;
+        return $ret;
         
     }