我有一个 wordpress 插件,它每周向我们的订阅者发送多达 3,200 份时事通讯。但是,它有时会在 800 封邮件后冻结,有时会在 1,200 封邮件后冻结(总是不同,没有特定的模式)。我们使用 turbo smtp 作为我们的主机。
这是我的做法:
我遍历存储所有邮件地址的表的行,并为每一行触发一个 ajax 调用。
// *** massmailer.php ****
// get total count of subscribers
$sqlAll = "SELECT * FROM subscribers";
$resultAll = mysql_query($sqlAll);
$numrowsAll = mysql_num_rows($resultAll);
// send mail for each subscriber, increasing row pointer $i each time
$sql = "SELECT * FROM subscribers LIMIT $i, 1";
$result = mysql_query($sql);
while ($guy = mysql_fetch_array($result)):
$mail = new PHPMailer();
$mail->Host = 'pro.turbo-smtp.com';
.... (other smtp settings here)
$mail->Send();
$i ++; // increase the row pointer by 1
// if row is NOT the last in the table, repeat this step for the next row
if ($i < $numrowsAll) {
echo "<script>$('#placeholder_massmailer').append($('<div>').load('massmailer.php?i=<? echo $i ?>'))</script>";
}
endwhile;
它工作得很好,但有时,$.load ajax 调用接缝在一定数量的 ajax 调用后冻结。
我应该使用其他架构吗?$.post 更适合这个吗?它作为 wordpress 插件的一部分工作;当它冻结时,我注意到 wordpress 尝试发送“心跳”ajax 调用?
谢谢马蒂亚斯