WordPress MU优化表的脚本


  WordPress MU由于每建立一个新的用户都会自动建立十多张表,因此当注册大量用户的时候会建立非常多的表,引起系统的性能出现问题,我这里写了一段脚本,可以将WordPress MU中的不活动用户(从没有发布文章的用户)进行删除,以节约系统资源。PHP脚本源代码如下:

<?php

    $mysql_host  = "localhost";
    $mysql_user  = "root";
    $mysql_pass  = "";
    $mysql_db  = "wordpress";

    $mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass)
    or die ("Cannot make the connection");
    mysql_select_db($mysql_db, $mysql_mylink)
    or die ("Cannot connect to the database");

    $strsql="select * from wp_blogs where blog_id>2  ";

    $rs_query = mysql_query($strsql);
    $alls=mysql_num_rows($rs_query);

    while (($RS = mysql_fetch_array($rs_query))) {
          extract($RS);
    $blogid=$RS["blog_id"];

    $query2 = "select * from wp_".$blogid."_posts ";
    $result = mysql_query($query2);
    $num= mysql_num_rows($result);
    //print $num;
    if ($num<=2) {
  print "DROP TABLE IF EXISTS wp_".$blogid."_comments;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_links ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_options ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_postmeta ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_posts ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_terms ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_term_relationships ;";
     print "DROP TABLE IF EXISTS wp_".$blogid."_term_taxonomy ;";
  print "DELETE from wp_blogs where blog_id=".$blogid.";";
    }
    }

    mysql_close ();

?>

  由此看出,WordPress MU使用起来实在不怎么样,多表结构设计的可能有问题,会带来很多麻烦。