dongqian0763 2009-05-12 09:06
浏览 58
已采纳

一个cron作业会杀死最后一个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.

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);

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.

Any help would be appreciated.

Thank you!

EDIT: My cron looks like:

*/1 * * * * php /path_to_file/convert.php
  • 写回答

3条回答 默认 最新

  • douying0108 2009-05-12 09:29
    关注

    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.

    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
    

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试