わかりました、ここで質問するのは初めてです。私の問題は、根底にたどり着くのが難しいほど厄介です。ストーリーは次のようになります: 私はこの小さなシステムを持っており、大量の電子メールの招待状 (スパムではない) を送信しています。したがって、賢明なことに、私は PHP 関数 mail() を使用せず、Mail、Mail_Queue、Net_SMTP などの PEAR クラスを使用します。唯一の問題は、エラー ログが次のような大量のエラーでいっぱいになることです。
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
メールキューを初期化するコードは次のとおりです(ニュースレターと呼ばれるクラス内)
//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;
}
問題は、私が書いたコードのすべての行を再確認したところ、それが機能していることです。唯一の問題は、メールの送信を拒否する場合があることです。返信ありがとうございます。