douyang5943 2009-12-18 13:40
浏览 28
已采纳

php阻止邮件的最大执行时间限制[重复]

This question already has an answer here:

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?

</div>
  • 写回答

3条回答 默认 最新

  • doushi3202 2009-12-18 13:43
    关注

    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:

    When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

    For instance:

    foreach ($emails as $email) {
        set_time_limit(30);
        send($email, ...);
    }
    

    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:

    php -c /custom/directory/my_php.ini my_script.php
    

    Where my_php.ini may specify:

    max_execution_time = 0     ; (unlimited)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100