PHP PEAR集装箱错误(PHP PEAR Container error)

2019-11-04 18:49发布

Allrighty,这是我第一次在这里提出一个问题。 我的问题是尴尬的,因为它是很难获得的底部。 故事是这样的:我有这样的小系统,它发送电子邮件邀请(不是垃圾邮件)的很多。 因此,采取明智的态度,我不使用PHP函数邮件(),我使用PEAR类,如邮件,Mail_Queue,Net_SMTP等。唯一的问题是,我的错误日志充满了吨这样的错误:

PHP Notice:  Error in sending mail: 
Mail Queue Error: Cannot initialize container in /usr/lib/php/PEAR.php on line 873

然后,当然的:

[18-Feb-2011 17:38:44] PHP Fatal error:  
Allowed memory size of 33554432 bytes exhausted 
(tried to allocate 3 bytes) in /usr/lib/php/PEAR.php on line 844

下面是其中inits邮件队列(名为通讯类中)的代码

//I know passing the DSN as the string is kind of deprecated, 
//but it;'s the only way it works on my system
$dsn ="mysql://$db_user:$db_pass@$db_host/$db_name";
$db_options = array();
$db_options['type']       = 'db';
$db_options['dsn']        = $dsn;
$db_options['mail_table'] = TABLE_QUEUE;

$this->host = '-- valid host here --';//data in these strings has been obscured
$this->username = '-- valid username here --';
$this->password = '-- valid password here --';

//optionally, a 'dns' string can be provided instead of db parameters.
//look at DB::connect() method or at DB or MDB docs for details.
//you could also use mdb container instead db
//$server = isset($_SERVER['SERVER_NAME'])?$_SERVER['SERVER_NAME']:'localhost';
$mail_options = array(
    'driver'   => 'smtp',
    'host'     => $this->host,
    'port'     => 25,
    'auth'     => true,
    'username' => $this->username,
    'password' => $this->password,
);
$this->mail_queue = new Mail_Queue($db_options, $mail_options);

一些更多的代码的路线,

public function sendChunk($start, $count)
{
    global $db;
    $ids = $db->get_results("SELECT DISTINCT id_user as id FROM ".TABLE_QUEUE);
    $ret = array();
    foreach ($ids as $id)
        $ret[] = $id->id;
    unset($ids);        
    $this->mail_queue->sendMailsInQueue($count, $start, 1);
    return true;
}

问题是,我双重检查的代码,我写的每一行,和它做它的工作。 唯一的问题是,有时它拒绝发送的任何邮件。 在此先感谢答复。

Answer 1:

我切换到MDB2代替DB的

$db_options['type']       = 'db';

$db_options['type']       = 'mdb2';

这有助于在照顾的内存排气问题,我现在还在找照顾初始化容器的/usr/lib/php/PEAR.php问题

好吧发现集装箱错误的解决方案:应用这个补丁http://svn.php.net/viewvc/pear/packages/Mail_Queue/trunk/Mail/Queue.php?r1=303876&r2=309126



Answer 2:

  1. 尝试限制的结果。 在SELECT语句使用限制。

  2. 尝试刷新旧主queye。



文章来源: PHP PEAR Container error