dongquming3255 2015-11-05 10:39
浏览 357

使用每15分钟运行一次的cron作业,每月执行一次

What I have: I have an existing cron job file that runs daily every 15 minutes (e.g. 1.10pm, 1.25pm, 1.40pm, 1.55pm), to check in the database for emails to be sent. I am using PHP and mySQL.

My issue: Due to a limit by the hosting, I have to use the same cron job file for another task - check the database at every end of the month.

My question 1: I only want the check to be done once on that day - would my following solution work? If I don't want to update the database that I have done the check already, I will have to set the task to only be done if the time now is equal to 8.55am (a timing that the cron job would run at). So if the cron job runs at 8.55am, it would do

$TimeNow = new DateTime();
$TimeNow = $TimeNow->format('H:i');
$TimeToRun = new DateTime('8:55');
$TimeToRun = $TimeToRun->format('H:i');
if ($TimeNow == $TimeToRun) {check database}

My question 2: Would the following work to check if it is the end of the month? What can I do to check if this works because it is not the end of the month now?

if(gmdate('t') == gmdate('d')){} 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改