简体   繁体   English

如何让我的 PEAR::Mail 实现更快地发送批量电子邮件?

[英]How can I make my PEAR::Mail implementation faster for sending bulk emails?

I am using two email templates and tested performance:我正在使用两个 email 模板并测试了性能:

  1. 100 emails with 25 products per email took 24 seconds.每个 email 包含 25 个产品的 100 封电子邮件耗时 24 秒。
  2. 100 emails with 12 products per email took 16 seconds.每个 email 包含 12 个产品的 100 封电子邮件耗时 16 秒。

All images (eg logos, banners, products) are text that invoke URLs where images are hosted on the server).所有图像(例如徽标、横幅、产品)都是调用图像托管在服务器上的 URL 的文本)。

I feel that the increase in time (from 16 to 24 seconds just for 100 emails) is dramatic, considering that I am only adding a few KB per product.我觉得时间的增加(从 16 秒到 24 秒仅 100 封电子邮件)是惊人的,因为我只为每个产品添加了几 KB。 If this is happening only sending 100 emails, the impact sending thousands of emails in terms or time and performance to complete the sends would be high.如果这种情况仅发送 100 封电子邮件,那么发送数千封电子邮件在完成发送的时间和性能方面的影响会很大。 My code uses this:我的代码使用这个:

....
require_once "/.../ea-php70/root/usr/share/pear/Mail.php";
$params['sendmail_path'] = '/usr/lib/sendmail';
$mail_object =& Mail::factory('sendmail', $params);
$timeoutSet = set_time_limit(18000); // set script time out to 5 hours 
...
for ($i = 1; $i <= 100; $i++) {
    ...
    $_mail = $mail_object->send($recipients, $headers, $sendContent); 
    ....
}
....

How can I make my PEAR::Mail implementation faster for sending bulk emails?如何让我的 PEAR::Mail 实现更快地发送批量电子邮件? I am suspecting that maybe my server is throttling emails or that I need to change some PEAR::Mail settings, or maybe use SMTP instead of Sendmail.我怀疑我的服务器可能正在限制电子邮件,或者我需要更改一些 PEAR::Mail 设置,或者可能使用 SMTP 而不是 Sendmail。 Any ideas?有任何想法吗? Thank you.谢谢你。

UPDATE 1:更新 1:

I have an 8 core, 16 thread processor.我有一个 8 核 16 线程处理器。 One thing I have done is to run my script in parallel from different tabs of the web browser so that for example instead of taking 4 minutes for sending 8000 emails, it only takes 1 minute because I send them in 4 batches of 2000 emails each, running the script simultaneously in 4 parallel and independent processes.我所做的一件事是从 web 浏览器的不同选项卡并行运行我的脚本,例如,发送 8000 封电子邮件不需要 4 分钟,只需要 1 分钟,因为我分 4 批发送它们,每批 2000 封电子邮件,在 4 个并行且独立的进程中同时运行脚本。 I am trying to find other ways to expedite even more this CPU intensive task and I am wondering if PEAR::Mail has some settings that I can modify to send emails faster.我正在尝试寻找其他方法来加快这项 CPU 密集型任务,我想知道PEAR::Mail是否有一些设置可以修改以更快地发送电子邮件。

The time increases considerably when you send the same number of e-mails but increase the number of products that are shown in each e-mail.当您发送相同数量的电子邮件但增加每封电子邮件中显示的产品数量时,时间会大大增加。 This indicates that not the sending of the e-mails is the problem, but the creation of the mail content.这表明问题不是电子邮件的发送,而是邮件内容的创建。

If all mails contain the same products, then generate the content only once, and re-use that for each e-mail.如果所有邮件都包含相同的产品,则只生成一次内容,并为每封电子邮件重复使用该内容。

If you have personalized e-mails, generate the non-personalized mail content only once and re-use that.如果您有个性化的电子邮件,则只生成一次非个性化的邮件内容并重复使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM