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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧