一个cron作业会杀死最后一个cron执行吗?

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

似乎当执行下一个cron时,它“杀死”最后一个cron执行。
我添加了以下PHP函数:</ p>

  ignore_user_abort(true); 
</ code> </ pre>

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

任何帮助都将不胜感激。</ p>

谢谢!</ p>

编辑:
我的cron看起来像:</ p>

  * / 1 * * * * php / path_to_file /  convert.php 
</ code> </ pre>
</ div>

展开原文

原文

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

dongyu5482
dongyu5482 似乎cron作业没有覆盖最后的工作,PHP代码中有一些错误。我添加了一个检查,以确保它退出,但添加一个Sander提到的完美的临时锁文件。谢谢!
11 年多之前 回复
douchun5976
douchun5976 没有错误出现,我也将时间限制设置为0。我忘了早些时候提到我的cron看起来像:<pre>*/1****php/path_to_file/convert.php</pre>谢谢!
11 年多之前 回复
drf21989
drf21989 你检查了PHP错误日志吗?您是否使用set_time_limit将时间限制设置为0?
11 年多之前 回复

3个回答

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');
doudouxuqh198138
doudouxuqh198138 cron不会杀死进程。 脚本(或脚本调用的东西)以自己的方式进入。
11 年多之前 回复



cron </ code>本身不会停止正在运行的作业的前一个实例,如果有问题,那就是 几乎可以肯定你的PHP做的事情。 您需要发布该代码。</ p>
</ div>

展开原文

原文

cron itself won't stop a previous instance of a job running so, if there's a problem, there's almost certainly something in your PHP doing it. You'll need to post that code.



不,它不会。 您可以通过创建脚本在每次运行时检查的锁定文件来保持第二个进程无法运行。 如果文件存在,则不会运行。 如果合适,这也应该与最大执行时间一起使用,以便一个进程不会无限期地停止将来的执行。 锁文件可以是一个名为/tmp/foo.lock.


</ div>的空纯文本文件

展开原文

原文

No, it will not. You can keep a second process from running by creating a lock file that the script checks for on each run. If the file exists, it does not run. This should also, if appropriate, be used in conjunction with a maximum execution time so that one process does not stall future executions indefinitely. The lock file can just be an empty plain text file called /tmp/foo.lock.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐