给更新昨日发帖数进行日志记录
打开include/db_mysql.class.php
在
- function query($sql, $type = '') {
- global $debug, $discuz_starttime, $sqldebug, $sqlspenttimes;
复制代码
下添加
- if(strpos($sql,'historyposts')){
- writelog('historyposts_log', "SQL语句:".$sql.";\r\n执行页面:".CURSCRIPT."\r\n执行时间:".time()."\r\n\r\n\r\n");
- }
复制代码
日志记录文件会在 forumdata/logs目录下
通过日志记录分析发现,在非常接近的时间内执行了两次计划任务,有可能是在高并发的情况下两个人分别执行了计划任务导致的,
临时的存在有点问题的修正方法
include\crons\todayposts_daily.inc.php 文件中
把
- $query = $db->query("SELECT value FROM {$tablepre}settings WHERE variable='historyposts'");
- $historypost = $db->result($query, 0);
- $hpostarray = explode("\t", $historypost);
- $historyposts = $hpostarray[1] < $yesterdayposts ? "$yesterdayposts\t$yesterdayposts" : "$yesterdayposts\t$hpostarray[1]";
- $db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('historyposts', '$historyposts')");
- $db->query("UPDATE {$tablepre}forums SET todayposts='0'");
- require_once DISCUZ_ROOT.'./include/cache.func.php';
- $_DCACHE['settings']['historyposts'] = $historyposts;
- updatesettings();
复制代码
改为
- if($yesterdayposts!=0){
- $query = $db->query("SELECT value FROM {$tablepre}settings WHERE variable='historyposts'");
- $historypost = $db->result($query, 0);
- $hpostarray = explode("\t", $historypost);
- $historyposts = $hpostarray[1] < $yesterdayposts ? "$yesterdayposts\t$yesterdayposts" : "$yesterdayposts\t$hpostarray[1]";
- $db->query("REPLACE INTO {$tablepre}settings (variable, value) VALUES ('historyposts', '$historyposts')");
- $db->query("UPDATE {$tablepre}forums SET todayposts='0'");
- require_once DISCUZ_ROOT.'./include/cache.func.php';
- $_DCACHE['settings']['historyposts'] = $historyposts;
- updatesettings();
- }
此方法在昨日发帖数真正为零的情况下也不会执行计划任务去更新昨日发帖数,导致论坛的昨日发帖数始终不为0