今天分享一下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'));```
请登录后发表评论
注册
停留在世界边缘,与之惜别