PHP PEAR 容器错误

发布于 2024-10-18 02:42:32 字数 2051 浏览 2 评论 0原文

好吧,这是我第一次在这里提问。我的问题很尴尬,也很难弄清楚。 故事是这样的:我有一个小系统,它发送大量电子邮件邀请(不是垃圾邮件)。所以,明智的做法是,我不使用 PHP 函数 mail(), 我使用 PEAR 类,如 Mail、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

这是初始化邮件队列的代码(在一个名为 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);

还有一些代码,

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

问题是,我仔细检查了我写的每一行代码,它都在完成它的工作。唯一的问题是有时它拒绝发送任何邮件。 预先感谢您的回复。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不语却知心 2024-10-25 02:42:32

我切换到 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

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

此岸叶落 2024-10-25 02:42:32
  1. 尝试限制结果。在 select 语句中使用 limit 。

  2. 尝试冲洗旧的主管道。

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

  2. Try to flush the old main queye.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文