• <bdo id='WCt12'></bdo><ul id='WCt12'></ul>
    <legend id='WCt12'><style id='WCt12'><dir id='WCt12'><q id='WCt12'></q></dir></style></legend>
  1. <small id='WCt12'></small><noframes id='WCt12'>

  2. <tfoot id='WCt12'></tfoot>
  3. <i id='WCt12'><tr id='WCt12'><dt id='WCt12'><q id='WCt12'><span id='WCt12'><b id='WCt12'><form id='WCt12'><ins id='WCt12'></ins><ul id='WCt12'></ul><sub id='WCt12'></sub></form><legend id='WCt12'></legend><bdo id='WCt12'><pre id='WCt12'><center id='WCt12'></center></pre></bdo></b><th id='WCt12'></th></span></q></dt></tr></i><div id='WCt12'><tfoot id='WCt12'></tfoot><dl id='WCt12'><fieldset id='WCt12'></fieldset></dl></div>

      如何每分钟多次运行 Cronjobs?

      时间:2023-08-17
        <bdo id='lJaew'></bdo><ul id='lJaew'></ul>

          <tbody id='lJaew'></tbody>

          <legend id='lJaew'><style id='lJaew'><dir id='lJaew'><q id='lJaew'></q></dir></style></legend>

          <small id='lJaew'></small><noframes id='lJaew'>

          • <i id='lJaew'><tr id='lJaew'><dt id='lJaew'><q id='lJaew'><span id='lJaew'><b id='lJaew'><form id='lJaew'><ins id='lJaew'></ins><ul id='lJaew'></ul><sub id='lJaew'></sub></form><legend id='lJaew'></legend><bdo id='lJaew'><pre id='lJaew'><center id='lJaew'></center></pre></bdo></b><th id='lJaew'></th></span></q></dt></tr></i><div id='lJaew'><tfoot id='lJaew'></tfoot><dl id='lJaew'><fieldset id='lJaew'></fieldset></dl></div>
            1. <tfoot id='lJaew'></tfoot>
                本文介绍了如何每分钟多次运行 Cronjobs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我创建了一个电子邮件队列数据库表.我将把我的 PHP 应用程序需要发送的所有电子邮件插入到这个表中.

                I created a Email-Queue database table. I will insert all Emails my PHP application needs to send into this table.

                另一个 PHP 脚本将查找所有未发送的电子邮件并发送它们.

                Another PHP script will then look for all unsent Emails and sends them.

                我使用 cronjobs 运行此脚本.不幸的是,cronjobs 每分钟最多只能运行一次.所以在最坏的情况下,用户必须等待一分钟,直到他的电子邮件真正被发送.

                I run this script using cronjobs. Unfortunately cronjobs can run only at a maximum of once per minute. So in the worst-case a user has to wait one minute until his Email is really going to be sent.

                我目前的解决方法是使用额外的 sleep 参数调用脚本并复制 cronjobs.

                My current idea for a workaround is calling the script with an addtional sleep parameter and duplicating the cronjobs.

                示例:

                * * * * * curl emails.php?sleep=0 >/dev/null 2>&1
                * * * * * curl emails.php?sleep=10 >/dev/null 2>&1
                * * * * * curl emails.php?sleep=20 >/dev/null 2>&1
                * * * * * curl emails.php?sleep=30 >/dev/null 2>&1
                * * * * * curl emails.php?sleep=40 >/dev/null 2>&1
                * * * * * curl emails.php?sleep=50 >/dev/null 2>&1
                

                在上面的示例中,脚本将每 10 秒运行一次.emails.php 脚本的第一行是:

                In the above example the script would run every 10 seconds. The first line of the emails.php Script would be:

                sleep($_REQUEST['sleep']);
                

                推荐答案

                对于初学者,我建议使用 PHP 的命令行版本,而不是使用 curl 来调用脚本.然后,您可以创建一个具有合理生命周期的 PHP 脚本,该脚本不受必须在给定时间段内输出响应的限制.

                For starters, I'd recommend using the command line version of PHP rather than using curl to call a script. You can then create a PHP script with a sensible lifetime that isn't constrained by having to output a response within a given time period.

                因此,您可以在 PHP 脚本中简单地睡眠/检查电子邮件/传输/睡眠等,而不是不必要地使用 cron.

                As such, you can then simply sleep/check for emails/transmit/sleep, etc. within the PHP script rather than needlessly using cron.

                此外,我会注意确保多个 PHP 脚本不会同时在数据库表上运行,无论是使用 pid 文件还是数据库设置方法(如果给定的文件/设置存在/已设置),中止处理)或通过在开始周期的检查电子邮件"部分之前检查脚本运行的时间来合理地计时 cron 作业并限制脚本的最大处理时间.

                Additionally, I'd take care to ensure that multiple PHP scripts aren't operating on the database table at the same time, either by using a pid file or database setting approach (if a given file/setting exists/is set, abort processing) or by sensibly timing the cron job and limiting the maximum processing time of the script by checking how long it's been running for prior to beginning the "check for emails" portion of the cycle.

                这篇关于如何每分钟多次运行 Cronjobs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Ubuntu 上为 php 执行 Cron 作业 下一篇:在 PHP 中使用 cron 管理器

                相关文章

                <small id='WN3k9'></small><noframes id='WN3k9'>

                <i id='WN3k9'><tr id='WN3k9'><dt id='WN3k9'><q id='WN3k9'><span id='WN3k9'><b id='WN3k9'><form id='WN3k9'><ins id='WN3k9'></ins><ul id='WN3k9'></ul><sub id='WN3k9'></sub></form><legend id='WN3k9'></legend><bdo id='WN3k9'><pre id='WN3k9'><center id='WN3k9'></center></pre></bdo></b><th id='WN3k9'></th></span></q></dt></tr></i><div id='WN3k9'><tfoot id='WN3k9'></tfoot><dl id='WN3k9'><fieldset id='WN3k9'></fieldset></dl></div>

                  <tfoot id='WN3k9'></tfoot>
                1. <legend id='WN3k9'><style id='WN3k9'><dir id='WN3k9'><q id='WN3k9'></q></dir></style></legend>
                    <bdo id='WN3k9'></bdo><ul id='WN3k9'></ul>