【Emlog】emlog程序发送文章和更新缓存卡顿或者很慢的解决办法

emlog
Emlog基于PHP MYSQL操作环境,因此缓存来自MYSQL数据库,以加快缓存速度,是为了加快MYSQL的查询速度

  对于MYSQL查询优化,索引编制等,有一点很重要,例如“ SELECT *”这样的SQL查询应减少使用

  当表中的字段中存在“ NULL”值时,查询将非常慢,而当数据量很大时查询也会变慢!

  所以有两个优化方向来最小化数据库中的NULL值(空字符串)

  二是优化SQL查询语句并建立索引

  然后对于EMLOG缓存,我们可以对其进行优化

  这里需要在用户表数据中处理此站点的优化,因为由于用户过多,用户缓存数据特别慢。

1、用户缓存修改方法:

打开根目录下的“include\lib\cache.php”将用户数据缓存这里替换一下,代码如下:
/**
 * 用户信息缓存
 */
private function mc_user() {
$user_cache = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "user");
while ($row = $this->db->fetch_array($query)) {
    $photo = array();
    $avatar = '';
    if(!empty($row['photo'])){
        $photosrc = str_replace("../", '', $row['photo']);
        $imgsize = chImageSize($row['photo'], Option::ICON_MAX_W, Option::ICON_MAX_H);
        $photo['src'] = htmlspecialchars($photosrc);
        $photo['width'] = $imgsize['w'];
        $photo['height'] = $imgsize['h'];
        $avatar = strstr($photosrc, 'thum') ? str_replace('thum', 'thum52', $photosrc) : preg_replace("/^(.*)\/(.*)$/", "\$1/thum52-\$2", $photosrc);
        $avatar = file_exists('../' . $avatar) ? $avatar : $photosrc;
    }
    $row['nickname'] = empty($row['nickname']) ? $row['username'] : $row['nickname'];
    $user_cache[$row['uid']] = array(
        'photo' => $photo,
        'avatar' => $avatar,
        'name_orig' => $row['nickname'],
        'name' => htmlspecialchars($row['nickname']),
        'mail' => htmlspecialchars($row['email']),
        'des' => htmlClean($row['description']),
        'ischeck' => htmlspecialchars($row['ischeck']),
        'role' => $row['role'],
        );
}
$cacheData = serialize($user_cache);
$this->cacheWrite($cacheData, 'user');
}
改代码为:

/**
 * 用户信息缓存
 */
private function mc_user() {
    $user_cache = array();
    $query = $this->db->query("SELECT uid,username,nickname,role,ischeck,photo,email,description FROM " . DB_PREFIX . "user");
    while ($row = $this->db->fetch_array($query)) {
        // $photo = array();
        /*
        $avatar = '';
        if(!empty($row['photo'])){
            $photosrc = str_replace("../", '', $row['photo']);
            $imgsize = chImageSize($row['photo'], Option::ICON_MAX_W, Option::ICON_MAX_H);
            $photo['src'] = htmlspecialchars($photosrc);
            $photo['width'] = $imgsize['w'];
            $photo['height'] = $imgsize['h'];
            $avatar = strstr($photosrc, 'thum') ? str_replace('thum', 'thum52', $photosrc) : preg_replace("/^(.*)\/(.*)$/", "\$1/thum52-\$2", $photosrc);
            $avatar = file_exists('../' . $avatar) ? $avatar : $photosrc;
        }*/
        $row['nickname'] = empty($row['nickname']) ? $row['username'] : $row['nickname'];
        $user_cache[$row['uid']] = array(
            'photo' => $row['photo'],
            'avatar' => $row['photo'],
            'name_orig' => $row['nickname'],
            'name' => htmlspecialchars($row['nickname']),
            'mail' => htmlspecialchars($row['email']),
            'des' => htmlClean($row['description']),
            'ischeck' => htmlspecialchars($row['ischeck']),
            'role' => $row['role'],
            );
    }
    $cacheData = serialize($user_cache);
    $this->cacheWrite($cacheData, 'user');
}

2、emlog优化的核心:

打开“admin\save_log.php”文件搜索:
// 源代码
$CACHE->updateCache();
// 修改为:
$CACHE->updateCache(array('sta', 'tags', 'newlog', 'logsort', 'logtags'));


版权声明:《 【Emlog】emlog程序发送文章和更新缓存卡顿或者很慢的解决办法 》为作者风起兮原创文章,转载请注明原文地址!
最后编辑:2020-7-1 16:07:27
分享到:
赞(0)
发表评论 / Comment

用心评论~