且构网

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

每5秒运行一次php脚本

更新时间:2022-12-28 17:21:47

使用Cron作业脚本。获得30秒的间隔,您可以延迟5秒:

Use Cron job script. Get a 30 seconds interval , you could delay by 5 seconds:

-*/5-22 * * * sleep 5;your_script.php

上述脚本将在凌晨5点至10点运行

The above script will run 5am to 10 pm

另一种选择是

You need to write a shell script like this that sleeps on the specified interval and schedule that to run every minute in cron:

#!/bin/sh
# Script: delay_cmd
sleep $1
shift
$*

然后使用您的参数计划在cron中运行:delay_cmd 5 mycommand参数

Then schedule that to run in cron with your parameters: delay_cmd 5 mycommand parameters