एस्क्रोनस पृष्ठभूमि प्रक्रिया के लिए कतार में ईमेल रखने के लिए Zend_Queue का उपयोग करें। पृष्ठभूमि में कतार को संसाधित करने के लिए आपको क्रॉन नौकरी की आवश्यकता होगी।
protected function _enqueueEmail(WikiEmailArticle $email)
{
static $intialized = false;
if (!$initialized) {
$this->_initializeMailQueue("wikiappwork_queue");
$initialized = true;
}
$this->_mailQueue->send(serialize($email));
}
protected function _initializeMailQueue()
{
/* See: 1.) http://framework.zend.com/manual/en/zend.queue.adapters.html and
* 2.) Zend/Queue/Adapter/Db/mysql.sql.
*/
$ini = Zend_Controller_Front::getInstance()->getParam('bootstrap')
->getOptions();
$queueAdapterOptions = array('driverOptions' => array(
'host' => $ini['resources']['multidb']['zqueue']['host'],
'username' => $ini['resources']['multidb']['zqueue']['username'],
'password' => $ini['resources']['multidb']['zqueue']['password'],
'dbname' => $ini['resources']['multidb']['zqueue']['dbname'],
'type' => $ini['resources']['multidb']['zqueue']['adapter']),
'name' => $ini['resources']['multidb']['zqueue']['queueName']);
$this->_mailQueue = new Zend_Queue('Db', $queueAdapterOptions);
}
क्रॉन जॉब के लिए
फिर, जैसे
<?php
use \Wiki\Email\WikiEmailArticle;
// Change this define to correspond to the location of the wikiapp.work/libary
define('APPLICATION_PATH', '/home/kurt/public_html/wikiapp.work/application');
set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_PATH . '/../library',
get_include_path(),
)));
// autoloader (uses closure) for loading both WikiXXX classes and Zend_ classes.
spl_autoload_register(function ($className) {
// Zend classes need underscore converted to PATH_SEPARATOR
if (strpos($className, 'Zend_') === 0) {
$className = str_replace('_', '/', $className);
}
$file = str_replace('\\', '/', $className . '.php');
// search include path for the file.
$include_dirs = explode(PATH_SEPARATOR, get_include_path());
foreach($include_dirs as $dir) {
$full_file = $dir . '/'. $file;
if (file_exists($full_file)) {
require_once $full_file;
return true;
}
}
return false;
});
// Load and parese ini file, grabing sections we need.
$ini = new Zend_Config_Ini(APPLICATION_PATH .
'/configs/application.ini', 'production');
$queue_config = $ini->resources->multidb->zqueue;
$smtp_config = $ini->email->smtp;
$queueAdapterOptions = array('driverOptions' => array(
'host' => $queue_config->host,
'username' => $queue_config->username,
'password' => $queue_config->password,
'dbname' => $queue_config->dbname,
'type' => $queue_config->adapter),
'name' => $queue_config->queuename);
$queue = new Zend_Queue('Db', $queueAdapterOptions);
$smtp = new Zend_Mail_Transport_Smtp($smtp_config->server, array(
'auth' => $smtp_config->auth,
'username' => $smtp_config->username,
'password' => $smtp_config->password,
'port' => $smtp_config->port,
'ssl' => $smtp_config->ssl
));
Zend_Mail::setDefaultTransport($smtp);
$messages = $queue->receive(10);
foreach($messages as $message) {
// new WikiEmailArticle.
$email = unserialize($message->body);
try {
$email->send();
} catch(Zend_Mail_Exception $e) {
// Log the error?
$msg = $e->getMessage();
$str = $e->__toString();
$trace = preg_replace('/(\d\d?\.)/', '\1\r', $str);
} // end try
$queue->deleteMessage($message);
} // end foreach
स्रोत
2011-05-26 00:07:49
यह एक भ्रामक जवाब के बाद से यदि क्रॉन का उपयोग नहीं है एक स्क्रिप्ट, स्क्रिप्ट टाइमआउट जब ईमेल भेजने एक मुद्दा हो जाएगा से पहले यातायात चिंता का विषय है। – rick
मुझे लगता है कि फिल का सुझाव है कि आप ईमेल भेजने के लिए क्रॉन का उपयोग करते हैं। उदाहरण के लिए, सूची समाप्त होने तक, केवल 30 मिनट, प्रत्येक 30 मिनट में भेजें। – grossvogel
लेकिन ऐसा लगता है कि वह सुझाव दे रहा है कि क्रॉन्टाब को उच्च यातायात के समाधान के रूप में इस्तेमाल किया जाना चाहिए? वैसे भी, हमें विपणन अभियान के साथ बहुत अधिक यातायात उत्पन्न करने के लिए बहुत भाग्यशाली होना चाहिए। संभावना है, यह कोई मुद्दा नहीं है। – rick