明天前的工作安排 [英] cron job minute before tomorrow

查看:81
本文介绍了明天前的工作安排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将通过curl触发对PHP文件的调用。我正在考虑让脚本每隔 23:59:59 或明天开始前一分钟执行一次。有什么最好的办法吗?仍然对cron设置感到困惑。

I am about to trigger a call to a PHP file via curl in a schedule basis. I am thinking of having the script to be executed every 23:59:59 or simply a minute before the day turns tomorrow. Any best approach for this? Quite confused still on the cron settings.

我需要确保第二天前一秒才跑步。

I need to ensure that I run at exactly a second before the next day.

推荐答案

要每天在23:59:00执行脚本,请使用以下命令:

To Execute a script every day at 23:59:00, use the following:

59 23 * * * root /path_to_file_from_root

不能使用Cron ,但这应该对您有用。

Seconds cannot be defined using Cron, but this should do for you.

要在23:59:59执行脚本,请使用PHP sleep( )函数将脚本执行延迟59秒。不过我建议58秒,以确保脚本不会延迟到午夜之后。

To execute the script at 23:59:59, use the PHP sleep() function to delay the execution of the script by 59 seconds. I would advise 58 seconds though, just to make sure the script doesn't delay until after midnight.

这是非常基本的操作,您可以将其做一点更复杂的运行测试,以通过检索时间并适当延迟来确保脚本始终在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

?>

这篇关于明天前的工作安排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆