dongmeng2509 2017-07-24 16:14
浏览 38
已采纳

Crontab没有运行重载页面的javascript

I have a php file that send emails to our clients who are expecting it and to ease the load on the server and to eliminate it looking like a spam server we reduce the flow to 40 emails every 20 seconds. This is done by using javascript to rerun the page every 20 seconds. The page itself reads from a data base and gets the next 40 email addresses, sends them, and then recycles until all are sent. Then the email list is reloaded from a duplicate table for the next cycle three weeks out.

Here is the javascript code that seems to not run when initiated by a cron job

<script language="JavaScript" type="text/javascript">
            setTimeout("location.href = \'PT_enrollment.php?sendDate='.$sendDate.'\'",20000); // milliseconds, so 10 seconds = 10000ms
            </script>

When I run this from my browser it does run correctly so I guess it is in the Cron Job functionality.

What am I missing? Is there a setting or parameter I need to set in the crontab or on the server so it runs correctly?

  • 写回答

2条回答 默认 最新

  • dousu8767 2017-07-24 19:10
    关注

    You could just have your PHP process sleep for those 20 seconds:

    $emails = // retrieve all emails from database
    $done = 0;
    
    foreach ($emails as $email) {
        // send email to $email
    
        $done++;
        if ($done % 40 == 0) { // every 40 emails
            sleep(20); // wait 20 seconds
        }
    }
    

    Ordinarily, cron jobs are run server-side via php-cli, which by default doesn't have a timeout. Some hosting providers run cron jobs by actually retrieving a URL via wget or curl, in which case you do have to account for a possible timeout. In that case, you can add set_time_limit(0); to your script to work around that.

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮