加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何在没有Crontab的情况下每两周在PHP中调用一个方法

发布时间:2020-12-13 22:27:51 所属栏目:PHP教程 来源:网络整理
导读:我想更新html中的div,每周只用php显示不同的内容,而不使用cron. 如何实现它?以下代码用于在第10天每2个月激活一次代码 但我猜逻辑会有所不同.如果可能的话,一些提示或示例将是伟大的!我很乐意听到你的消息! // check if current day is 10th and month is
我想更新html中的div,每周只用php显示不同的内容,而不使用cron.
如何实现它?以下代码用于在第10天每2个月激活一次代码
但我猜逻辑会有所不同.如果可能的话,一些提示或示例将是伟大的!我很乐意听到你的消息!

// check if current day is 10th and month is an even number
if (date('d')==10 && date('m') % 2 == 0) {
    // get todays-date (format: yyyymmdd)
    $today = date('Ymd'); 
    // get info about last run
    $last_run = variable_get('my_last_run',0);
    // check last run was not today
    if ($last_run!=$today) {
        // set last run to today
        variable_set('my_last_run',$today);

        /* Place your code here */

    }
}

解决方法

我刚刚更新了你的例子,现在它将在下周一发布:

$weekInYearNumber = (int)date('W');
$weekDayNumber = (int)date('w');
if ($weekDayNumber === 1 && $weekInYearNumber % 2 == 0) {
    // Rest of your code.
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读