PHP PEAR Container error

佐手、 提交于 2020-01-17 01:30:16

问题


Allrighty, it's the first time I ask a question here. My problem is as awkward as it is difficult to get to the bottom of. Story goes like this: I have this little system, which sends alot of e-mail invitations(not spam). So, being sensible, I don't use the PHP function mail(), I use PEAR classes like Mail, Mail_Queue, Net_SMTP, etc. Only problem is, my error logs fill up with tons of errors like this:

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

And then, of course:

[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

Here's the code which inits the mail queue(inside a class called Newsletter)

//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);

Some more code down the line,

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;
}

Problem is, I double checked every line of code I wrote, and it's doing it's job. Only problem is that sometimes it refuses to send any mails. Thanks in advance for replies.


回答1:


I switched to MDB2 instead of DB

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

to

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

this helped in taking care of memory exhaust problem, I am still looking to take care of initialize container in /usr/lib/php/PEAR.php problem

Ok found the solution for container errors: Apply this patch http://svn.php.net/viewvc/pear/packages/Mail_Queue/trunk/Mail/Queue.php?r1=303876&r2=309126




回答2:


  1. Try to limit result. using limit in your select statement.

  2. Try to flush the old main queye.



来源:https://stackoverflow.com/questions/5044063/php-pear-container-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!