我将在计划的基础上通过curl触发对PHP文件的调用.我想让脚本每23:59:59执行一次,或者只是在明天转一天前的一分钟.对此最好的方法是什么?仍然对cron设置感到困惑.
我需要确保在第二天之前运行一秒钟.
Man*_*nan 14
Minutes [0-59]
| Hours [0-23]
| | Days [1-31]
| | | Months [1-12]
| | | | Days of the Week [Numeric, 0-6]
| | | | |
* * * * * home/path/to/command/the_command.sh
59 23 * * * home/path/to/command/the_command.sh
Run Code Online (Sandbox Code Playgroud)
要在每天23:59:00执行脚本,请使用以下命令:
59 23 * * * root /path_to_file_from_root
Run Code Online (Sandbox Code Playgroud)
使用Cron无法定义秒数,但这应该适合您.
要在23:59:59执行脚本,请使用PHP sleep()函数将脚本的执行延迟59秒.我会建议58秒,只是为了确保脚本不会延迟到午夜之后.
这是非常基本的,您可以使它更复杂并运行测试以确保脚本始终在23:59:59运行,方法是检索时间并适当延迟.但这不应该是必要的.
<?php
// Any work that the script can do without altering the database, do here
// Delay the script by 58 seconds
sleep(58);
// Carry on with the rest of the script here, database updates etc
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6228 次 |
| 最近记录: |