【问题标题】:Run a script every few secconds [duplicate]每隔几秒钟运行一个脚本[重复]
【发布时间】:2018-09-24 16:23:00
【问题描述】:

我有一个 php 脚本,我需要每 4 秒运行一次,每天运行一小时,最好的方法是什么。我查找了一种使用 cron 和 sleep 的方法,也观看了,但是总体而言,最好的方法是什么?

观看

watch -n10 command args

cron:

* * * * * /foo/bar/your_script
* * * * * sleep 4; /foo/bar/your_script
* * * * * sleep 8; /foo/bar/your_script
* * * * * sleep 12; /foo/bar/your_script

【问题讨论】:

    标签: linux


    【解决方案1】:

    简而言之,使用 cron 似乎没有一种简单的方法可以做到这一点,因为 cron 的粒度为 60 秒。基本上你必须找到一种解决方法。

    您似乎已经遇到过的一种解决方法是让多个事件的开始时间偏移。例如。 Running a cron every 30 seconds

    另一个是在 PHP 脚本本身内进行更精细的调度。例如。在this answer

    此时,将您的 PHP 脚本设置为守护进程可能是有意义的:Run php script as daemon process

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-14
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 1970-01-01
      • 2012-04-25
      • 2017-05-08
      相关资源
      最近更新 更多