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

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型