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");
&nbsp ;   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 &quot ;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 ;&​​quot;;
   print "DELETE from wp_blogs where blog_id=".$blogid.";";
    }
    }

    mysql_close ();

?>

  由此看出,WordPress MU使用起來實在不怎麼樣,多表結構設計的可能有問題,會帶來很多麻煩。

文章轉載月光博客

Comments are closed.