關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • 提高 Apache 的 MaxClients 選項

    Posted on February 27th, 2009 Sam Tang 1 comment

    如果碰到網頁伺服器突然變慢,然後網頁服務停止,在 apache 的 error log 找到以下語句:

    [error] server reached MaxClients setting, consider raising the MaxClients setting

    那麼就是 Apache 超過最大連線數,如果是 Apache 2.0 的話便不用重新編譯,只要開啟 httpd.conf 修改 MaxClients 選項。


    StartServers 10
    MinSpareServers 10
    MaxSpareServers 15
    MaxClients 200
    MaxRequestsPerChild 10000

    完成後重新啟動 Apache 即可。


  • 用 PHP 查詢 MySQL Table 使用空間

    Posted on February 27th, 2009 Sam Tang No comments

    要查詢 MySQL 資料表所用的空間,雖然資料表是用 MyISAM 的話,可以直接用 ls 指令知道,但這個方法不可以用在 InnoDB 資料表上面。

    要計算資料表的容量,可以供用 MySQL 語句 "SHOW TABLE STATUS" 實現,然後將回傳的 Data_length 加 Index_length 即可。以下程式會擷取資料庫內所有資料表的使用空間:

    PHP:
    1. <?php
    2. $db_link = mysql_connect("localhost", "db_username", "db_password");
    3. mysql_select_db("db_name", $db_link);
    4.  
    5. $result = mysql_query("SHOW TABLE STATUS");
    6. while($rows = mysql_fetch_array($result)){
    7.     $total_size = $rows['Data_length'] + $rows['Index_length'];
    8.  
    9.     // return table size by KB or MB
    10.     if($total_size <1048576){
    11.         $total_size = $total_size / 1024;
    12.     }else{
    13.         $total_size = $total_size / 1024 / 1024;
    14.     }
    15.  
    16.     $tables[$rows['Name']] = sprintf("%.2f", $total_size);
    17. }
    18.  
    19. print_r($tables);


  • Ubuntu 安裝 terminus 及 Fixedsys 字型

    Posted on February 11th, 2009 Sam Tang 1 comment

    平日使用電腦習慣在終端機及寫程式時使用 terminus 字型,而以 plain 閱讀電郵則喜歡 Fixedsys 字型。但 Ubuntu 安裝也這兩種字型也沒有,以下是安裝以上兩種字型的方法:

    安裝 terminus
    在終端機打入以下指令即可:

    sudo apt-get install xfonts-terminus

    安裝 Fixedsys
    fixedsys 下載 fixedsys 的 ttf 檔,解壓後將 Fixedsys500c.ttf 複製到 /usr/share/fonts/truetype/,指令如下:

    sudo cp /path/Fixedsys500c.ttf /usr/share/fonts/truetype/
    sudo fc-cache -f -v

    這樣就可以使用 terminus 及 Fixedsys 字型 了。