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

      1. <small id='jFdet'></small><noframes id='jFdet'>

        <tfoot id='jFdet'></tfoot>

        cron 作业是否会终止最后的 cron 执行?

        时间:2023-08-17

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

        <tfoot id='cg3Gh'></tfoot>
        • <legend id='cg3Gh'><style id='cg3Gh'><dir id='cg3Gh'><q id='cg3Gh'></q></dir></style></legend>
            <bdo id='cg3Gh'></bdo><ul id='cg3Gh'></ul>

                    <tbody id='cg3Gh'></tbody>

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

                  本文介绍了cron 作业是否会终止最后的 cron 执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个执行 PHP 脚本的 cron 作业.cron 设置为每分钟运行一次,这仅用于测试目的.它正在执行的 PHP 脚本旨在将用户上传到服务器的视频转换为 Flash 格式(例如....flv).通过命令行手动执行脚本时,脚本执行良好,但是通过 cron 执行时,它开始正常,但一分钟后它就停止了.

                  I have a cron job the executes a PHP script. The cron is setup to run every minute, this is done only for testing purposes. The PHP script it is executing is designed to convert videos uploaded to the server by users to a flash format (eg... .flv). The script executes fine when manually doing it via command line, however when executing via cron it starts fine but after one minute it just stops.

                  似乎在执行下一个 cron 时它会杀死"最后一个 cron 执行.我添加了以下 PHP 函数:

                  It seems that when the next cron is executed it "kills" the last cron execution. I added the following PHP function:

                  ignore_user_abort(true);
                  

                  希望它不会中止最后一次执行,我测试将 cron 设置为每 5 分钟运行一次,效果很好,但是视频的转换可能需要 5 分钟以上,所以我需要弄清楚为什么它在什么时候停止另一个 cron 被执行.

                  In hopes that it would not abort the last execution, I tested setting the cron to run every 5 minutes, which works fine, however a conversion of a video may take over 5 minutes so I need to figure out why its stoping when another cron is executed.

                  任何帮助将不胜感激.

                  谢谢!

                  我的 cron 看起来像:

                  My cron looks like:

                  */1 * * * * php /path_to_file/convert.php
                  

                  推荐答案

                  我认为 cron 不会杀死任何进程.但是,cron 并不真正适合长时间运行的进程.此处可能发生的情况是,您的脚本在多次执行时会自行踩踏.例如,两个 PHP 进程可能同时尝试写入同一个文件.

                  I don't think cron kills any processes. However, cron isn't really suitable for long running processes. What may be happening here is that your script tramples all over itself when it is executed multiple times. For example, both PHP processes may be trying to write to the same file at the same time.

                  首先,确保您不仅查看 php 错误日志,还要尝试从 PHP 文件本身捕获输出.例如:

                  First, make sure you not only look in the php error log but also try to capture output from the PHP file itself. E.g:

                  */1 * * * * * php /path/to/convert.php & >> /var/log/convert.log
                  

                  您还可以使用简单的锁定文件来确保 convert.php 不会被多次执行.类似的东西:

                  You could also use a simplistic lockfile to ensure that convert.php isn't executed multiple times. Something like:

                  if (file_exists('/tmp/convert.lock')) {
                      exit();
                  }
                  
                  touch('/tmp/convert.lock');
                  // convert here
                  unlink('/tmp/convert.lock');
                  

                  这篇关于cron 作业是否会终止最后的 cron 执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:不使用 CRON 调度脚本 下一篇:创建没有 Cron 作业的计划任务

                  相关文章

                  <tfoot id='2d76w'></tfoot>

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

                      <small id='2d76w'></small><noframes id='2d76w'>