I’ve a script to send packages of 300-500 e-mails hour. That means that this script will be fired once a hour using cron or other feature.
The server has a max execution limit of 30secs and it’s not configurable.
I’ve been thinking if the pseudo-code below should work:
$time=time();
$count=0;
while(condition){
$count++;
send(email);
$now=time();
if($now-$time>=29){break;} //1sec margin
}
echo "$count e-mails sent";
Opinions?
Just to double-check that you can’t set the execution time, here are two suggestions.
You could simply call
set_time_limit()before sending an e-mail. According to the PHP docs:For instance:
Another option is via the cron. Since you are running PHP from a cron job, you can specify your own
php.ini. You could execute your script as follows:Where
my_php.inimay specify: