我使用这个代码发送电子邮件到我的列表使用我的服务器。过了一会儿,由于我的邮件列表很大,脚本超时了。
这个问题有解决办法吗?
我不想让服务器过载。是否有一个代码,我可以添加到我的脚本加载每个电子邮件与每行之间的时间?下面是我使用的PHP脚本
<?php
$emailaddress = file("email-list.txt"); // load from a flat file, assuming 1 email per line in the file
$emailsubject = "[title] title of my email";
$emailbody = file_get_contents("email-content.html");
$fromaddress = "my@3emailserver.com";
$i = count($emailaddress);
$z = 0;
// here we check how many email address's we have, if its is 0, then we don't start the email function
if ($i != 0)
{// start if
// Lets loop until we reach the count from email address arrar
while ($i != $z)
{// start while
// here we send the email to the varables from above, using the email array incrament
mail($emailaddress[$z], $emailsubject, $emailbody, "From: " .$fromaddress. "nX-Mailer: PHP 4.x");
// lets echo out that the email was sent
echo $z + 1 . " out of " . $i . " emails sent. (" . $emailaddress[$z] . ")<br>";
// increment the array one, so we get a new email address from the array
++$z;
}// end while
}//end if
else
{//start else
// we echo out that no emails where found in the array and end the script
echo "Warning: No emails in array.";
}// end else
?>
use
// sleep for 10 seconds
sleep(10);
php.ini默认设置max_execution_time为30秒。(检查你的php.ini)
使用set_time_limit函数修改时间(0= nollimit):
set_time_limit(0);
或者使用ini_set function:
ini_set('max_execution_time', 0);