微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想更新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.
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐