本文介绍了PHP PEAR容器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这是我第一次在这里提问。我的问题是尴尬的,因为它很难达到底部。
故事是这样的:我有这个小系统,发送大量的电子邮件邀请(而不是垃圾邮件)。所以,明智的,我不使用PHP函数mail(),
我使用PEAR类,如邮件,Mail_Queue,Net_SMTP等
只有问题是,我的错误日志填满了吨错误如下:

  PHP注意:发送邮件时出错:
邮件队列错误:无法初始化/ usr中的容器/lib/php/PEAR.php在线873

然后,当然:

  [2011年2月18日17:38:44] PHP致命错误:
允许内存大小为33554432字节耗尽
(试图分配3个字节)在第844行的/usr/lib/php/PEAR.php

这里是邮件队列中的代码(在一个叫做通讯的类里面)

  //我知道传递DSN作为字符串是不赞成的,
//但是它是在我的系统上工作的唯一方法
$ 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 =' - 这里的有效主机 - '; //这些字符串中的数据已被模糊
$ this-> username =' - 有效的用户名这里 - ';
$ this-> password =' - 此处有效的密码 - ';

//可选地,可以提供'dns'字符串而不是db参数。
//查看DB :: connect()方法或DB或MDB文档的详细信息。
//你也可以使用mdb容器,而不是db
// $ server = isset($ _ SERVER ['SERVER_NAME'])?$ _ SERVER ['SERVER_NAME']:'localhost'
$ mail_options = array(
'driver'=>'smtp',
'host'=> $ this->主机,
'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($ id作为$ id)
$ ret [] = $ id-> id;
unset($ ids);
$ this-> mail_queue-> sendMailsInQueue($ count,$ start,1);
返回true;
}

问题是,我仔细检查了我写的每一行代码,它在做这是工作。唯一的问题是有时它拒绝发送任何邮件。
提前感谢回复。

解决方案

我切换到而不是DB

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

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

这有助于照顾内存排气问题,我仍然希望照顾初始化容器 /usr/lib/php/PEAR.php 问题



确定发现容器错误的解决方案:
应用此补丁


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.

解决方案

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 patchhttp://svn.php.net/viewvc/pear/packages/Mail_Queue/trunk/Mail/Queue.php?r1=303876&r2=309126

这篇关于PHP PEAR容器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:48