站点垃圾评论数过多,不胜其烦,
1、浪费我的钱(磁盘占用量增加了100倍,磁盘可是按容量来计费的,包括备份快照)
2、浪费我的时间(打开站点和后台都变慢)
3、浪费心情💢(每次打开后台看到一堆待审的评论,尽管没有强迫症也难受,这个就不能忍了)
一、来看看评论的数据量和容量
1、数据量
mysql> select count(*) from wp_comments; +----------+ | count(*) | +----------+ | 106128 | +----------+ 1 row in set (0.08 sec)
2、容量
mysql> select -> table_schema as '数据库', -> table_name as '表名', -> table_rows as '记录数', -> truncate(data_length/1024/1024, 2) as '数据容量(MB)', -> truncate(index_length/1024/1024, 2) as '索引容量(MB)' -> from information_schema.tables -> where table_schema='niliu' -> order by data_length desc, index_length desc; +-----------+-----------------------------+-----------+------------------+------------------+ | 数据库 | 表名 | 记录数 | 数据容量(MB) | 索引容量(MB) | +-----------+-----------------------------+-----------+------------------+------------------+ | niliu | wp_comments | 87292 | 518.95 | 15.57 | | niliu | wp_posts | 2014 | 23.51 | 0.56 | | niliu | wp_usermeta | 124268 | 7.51 | 8.03 | | niliu | wp_users | 9535 | 2.51 | 3.51 | | niliu | wp_options | 235 | 1.07 | 0.03 | | niliu | wp_postmeta | 2183 | 0.39 | 0.20 | | niliu | wp_term_relationships | 591 | 0.04 | 0.01 | | niliu | wp_termmeta | 0 | 0.01 | 0.03 | | niliu | wp_term_taxonomy | 46 | 0.01 | 0.03 | | niliu | wp_commentmeta | 216 | 0.01 | 0.03 | | niliu | wp_terms | 46 | 0.01 | 0.03 | | niliu | midoks_weixin_robot_extends | 0 | 0.01 | 0.01 | | niliu | wp_links | 0 | 0.01 | 0.01 | | niliu | midoks_weixin_robot | 0 | 0.01 | 0.00 | | niliu | midoks_weixin_robot_reply | 0 | 0.01 | 0.00 | | niliu | midoks_weixin_robot_menu | 0 | 0.01 | 0.00 | +-----------+-----------------------------+-----------+------------------+------------------+ 16 rows in set (0.03 sec)
二、解决方法
1、限制评论频次
// 在主题文件中第一行加上如下限制代码
// wp-content/themes/twentytwelve/functions.php
注⚠️:我的主题是twentytwelve
add_filter('comment_flood_filter', 'suren_comment_flood_filter', 10, 3); function suren_comment_flood_filter($flood_control, $time_last, $time_new) { // 间隔时间 $seconds = 60; if (($time_new - $time_last) < $seconds) { $time = $seconds - ($time_new - $time_last); err ('评论过快!请' . $time . '秒后再次评论'); } else { return false; } }
2、使用插件
3、关闭评论入口
test
test2