Swift_MemorySpool::flushQueue PHP Method

flushQueue() public method

Sends messages using the given transport instance.
public flushQueue ( Swift_Transport $transport, string[] &$failedRecipients = null ) : integer
$transport Swift_Transport A transport instance
$failedRecipients string[] An array of failures by-reference
return integer The number of sent emails
    public function flushQueue(Swift_Transport $transport, &$failedRecipients = null)
    {
        if (!$this->messages) {
            return 0;
        }
        if (!$transport->isStarted()) {
            $transport->start();
        }
        $count = 0;
        $retries = $this->flushRetries;
        while ($retries--) {
            try {
                while ($message = array_pop($this->messages)) {
                    $count += $transport->send($message, $failedRecipients);
                }
            } catch (Swift_TransportException $exception) {
                if ($retries) {
                    // re-queue the message at the end of the queue to give a chance
                    // to the other messages to be sent, in case the failure was due to
                    // this message and not just the transport failing
                    array_unshift($this->messages, $message);
                    // wait half a second before we try again
                    usleep(500000);
                } else {
                    throw $exception;
                }
            }
        }
        return $count;
    }

Usage Example

 /**
  * Flushs the memory queue.
  *
  * @return  void
  */
 protected function flushMemoryQueue()
 {
     if ($this->memorySpool !== null) {
         $mailer = $this->getMailer();
         $transport = $mailer->getTransport();
         if ($transport instanceof \R3H6\MailSpool\Mail\SpoolTransport) {
             $failedRecipients = array();
             try {
                 $sent = $this->memorySpool->flushQueue($transport->getRealTransport(), $failedRecipients);
                 if (!$sent) {
                     throw new \RuntimeException('No e-mail has been sent', 1476304931);
                 }
             } catch (\Exception $exception) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog($exception->getMessage(), 'mail_spool', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
         }
     }
 }
All Usage Examples Of Swift_MemorySpool::flushQueue