Esempio n. 1
0
 public function processBouncesShutdown()
 {
     Process::releaseLock($this->process_id);
     # phpList::log()->addToReport('Connection status:'.connection_status());
     $this->finish('info', phpList::log()->getReport());
 }
Esempio n. 2
0
 /**
  * Shutdown function for execution on shutdown
  * @link http://php.net/manual/en/function.register-shutdown-function.php
  */
 public function shutdown()
 {
     #  phpList::log()->debug( "Script status: ".connection_status(), ['page' => 'porcessqueue']); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774
     phpList::log()->debug(s('Script stage') . ': ' . $this->script_stage, ['page' => 'porcessqueue']);
     $some = $this->processed;
     #$this->sent;# || $this->invalid || $this->notsent;
     if (!$some) {
         phpList::log()->debug(s('Finished, Nothing to do'), ['page' => 'porcessqueue']);
         $this->nothingtodo = 1;
     }
     $totaltime = Timer::get('process_queue')->elapsed(true);
     if ($totaltime > 0) {
         $msgperhour = 3600 / $totaltime * $this->sent;
     } else {
         $msgperhour = s('Calculating');
     }
     if ($this->sent) {
         phpList::log()->debug(sprintf('%d %s %01.2f %s (%d %s)', $this->sent, s('campaigns sent in'), $totaltime, s('seconds'), $msgperhour, s('msgs/hr')), ['page' => 'processqueue']);
     }
     if ($this->invalid > 0) {
         phpList::log()->debug(s('%d invalid email addresses', $this->invalid), ['page' => 'porcessqueue']);
     }
     if ($this->failed_sent > 0) {
         phpList::log()->debug(s('%d failed (will retry later)', $this->failed_sent), ['page' => 'porcessqueue']);
         foreach ($this->counters as $label => $value) {
             #  phpList::log()->debug(sprintf('%d %s',$value,s($label)),1,'progress', ['page' => 'porcessqueue']);
             phpList::log()->info(sprintf('%d %s', $value, s($label)), ['page' => 'processqueue']);
         }
     }
     if ($this->unconfirmed > 0) {
         phpList::log()->debug(sprintf(s('%d emails unconfirmed (not sent)'), $this->unconfirmed), ['page' => 'porcessqueue']);
     }
     /*
      * TODO: enable plugins
     foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
         $plugin->processSendStats($this->sent,$this->invalid,$this->failed_sent,$this->unconfirmed,$this->counters);
     }
     */
     Cache::flushClickTrackCache();
     Process::releaseLock($this->send_process_id);
     //finish("info",$report,$this->script_stage);
     //function finish ($flag,$campaign,$this->script_stage) {
     $subject = s('Maillist Processing info');
     if (!$this->nothingtodo) {
         phpList::log()->info(s('Finished this run'), ['page' => 'progress']);
         phpList::log()->info(s('%s of %s done', $this->sent, $this->counters['total_subscribers_for_campaign ' . $this->current_campaign->id]), ['page' => 'progress']);
     }
     //TODO:enable plugins
     /*
     if (!Config::TEST && !$this->nothingtodo && Config::get(('END_QUEUE_PROCESSING_REPORT'))) {
         foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
             $plugin->sendReport($subject,$campaign);
         }
     }
     */
     if ($this->script_stage < 5 && !$this->nothingtodo) {
         phpList::log()->info(s('Warning: script never reached stage 5') . "\n" . s('This may be caused by a too slow or too busy server') . " \n");
         //TODO: remove globals
     } elseif ($this->script_stage == 5 && (!$this->nothingtodo || isset($GLOBALS['wait']))) {
         # if the script timed out in stage 5, reload the page to continue with the rest
         $this->reload++;
         if (!Config::get('commandline') && $this->num_per_batch && $this->batch_period) {
             if ($this->sent + 10 < $this->original_num_per_batch) {
                 phpList::log()->debug(s('Less than batch size were sent, so reloading imminently'), ['page' => 'porcessqueue']);
                 $delaytime = 10;
             } else {
                 // TODO: we should actually want batch period minus time already spent.
                 // might be nice to calculate that at some point
                 phpList::log()->info(sprintf(s('Waiting for %d seconds before reloading'), $this->batch_period), ['page' => 'processqueue']);
                 $delaytime = $this->batch_period;
             }
             sleep($delaytime);
             /*Output::customPrintf(
                   '<script type="text/javascript">
                      document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d";
                   </script>',
                   $this->reload,
                   $this->sent,
                   $this->notsent
               );*/
         } else {
             /*Output::customPrintf(
                   '<script type="text/javascript">
                      document.location = "./?page=pageaction&action=processqueue&ajaxed=true&reload=%d&lastsent=%d&lastskipped=%d";
                   </script>',
                   $this->reload,
                   $this->sent,
                   $this->notsent
               );*/
         }
     } elseif ($this->script_stage == 6 || $this->nothingtodo) {
         /*
                      * TODO: enable plugins
                     foreach ($GLOBALS['plugins'] as $pluginname => $plugin) {
                         $plugin->campaignQueueFinished();
                     }*/
         phpList::log()->debug(s('Finished, All done'), 0, ['page' => 'porcessqueue']);
     } else {
         phpList::log()->debug(s('Script finished, but not all campaigns have been sent yet.'), ['page' => 'porcessqueue']);
     }
     if (!Config::get('commandline') && empty($_GET['ajaxed'])) {
         include_once "footer.inc";
     } elseif (Config::get('commandline')) {
         @ob_end_clean();
     }
     exit;
 }