且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何每X分钟运行一次cronjob?

更新时间:2022-12-26 12:44:45

crontab 文件中,字段是:

In a crontab file, the fields are:

  • 每小时的一分钟.
  • 一天中的几个小时.
  • 一个月中的第几天.
  • 一年中的一个月.
  • 星期几.

所以:

10 * * * * blah

表示每小时过去 10 分钟执行 blah.

means execute blah at 10 minutes past every hour.

如果您想每五分钟使用一次:

If you want every five minutes, use either:

*/5 * * * * blah

表示每分钟但仅每五分之一,或:

meaning every minute but only every fifth one, or:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * blah

对于不理解 */x 符号的旧 cron 可执行文件.

for older cron executables that don't understand the */x notation.

如果之后它仍然似乎不起作用,请将命令更改为:

If it still seems to be not working after that, change the command to something like:

date >>/tmp/debug_cron_pax.txt

并监视该文件以确保每五分钟写入一次内容.如果是这样,则说明您的 PHP 脚本有问题.如果没有,则您的 cron 守护进程有问题.

and monitor that file to ensure something's being written every five minutes. If so, there's something wrong with your PHP scripts. If not, there's something wrong with your cron daemon.