設計情境
 
啟用 Apache mod_deflate 網頁資料壓縮傳輸將可大提升 Apache 運作效能

(但需佔用些許CPU Loading)
 
PHP Memcache :  加速PHP Script 傳輸效率, 可使用 Memcached 來存 PHP session
 
使用安裝套件
 
libevent-1.4.13.1
 
 
 
OS: CentOS 5.4
 
Apache 2.2.3
 
PHP 5.3  Version
 
(一) mod_deflate  :  vi  /etc/httpd/conf/httpd.conf
 
         查尋關鍵字 "deflate" 確保此Module 是有載入而不是被駐解掉
 
    
       
        接者我們選擇在不礙眼地方加入以下幾行,儲存後離開
        
       <ifmodule mod_deflate.c>
       DeflateCompressionLevel 9
      AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
      AddOutputFilter DEFLATE js css     
       </ifmodule>
 
   
 
     接者我們重新啟動Apache 即可完成mod_deflate 設置
 
  
 
 (二)  memcached 安裝   :  我們利用yum 安裝 libevent-devel (ver.1.4.13.1) 版本算較新的,

          您也可以使用源瑪安裝
 
         yum -y install libevent-devel
 
   
 
         安裝 memcached 1.4.0
 
         tar -xzvf memcached-1.4.5.tar.gz
 
         cd memcached-1.4.5
.
         /configure –with-libevent=/usr/
 
         make
 
         make install  

         接者我們試圖啟動 memcached

          [參數說明] 

        -d 表示這是daemon,

       -m 表示會使用幾MB的記憶體來存放資料,

        -l表示會listen的IP位址,

       -p則是所listen的port,

       -u 啟動的user為誰,由於memcached預設不可以由root來啟動,

            所以你如果要用root來啟動,就要加。

       -c 同時間可以有多少個connection。

      /usr/local/bin/memcached -d -u root -m 30 127.0.0.1 -p 11211     

        
*您可以寫成一個sh讓開機時自動起用memcached

         *下圖我們察知11211 已經On 起來此Port可自定memcached 使用Port號*

    
   
 由於筆者使用"remi"套件升級apache 2.2.3  &  php 5.3  常發生預期設定須更正問題

        (問題一)  PHP Warning:  strtotime(): It is not safe to rely on the system's
 
                         timezone settings.
You are *required* to use the date.timezone 

                         settingorthe date_default_timezone_set() function. ....
 
                         等Messages
                        

                         解: 
vi /etc/php.ini    

                      請將此行前方; 去掉並修改為   date.timezone = "Asia/Taipei"

          (問題二)重新啟動Apache 時出現"FQDN"沒對應這確訊息

            解 : vi /etc/httpd/conf/httpd.conf           

            
#原來升級到PHP 5.3時, ServerName 此選項預設被 ";"被註解掉

            所以我們必須將";" 去掉,並修改成 ServerName  localhost:80 即可   

             

            

(二)  memcache 擴展程式安裝   : 

  
        
 tar -zxvf memcached-3.0.4.tgz

         cd memcached-2.2.4

         phpize && ./configure --enable-memcache && make  

       
*注意是否已安裝php-devel,若無是無法使用phpize這隻程式l*

          make install

         接者我們編輯 /etc/php.ini  於Dynamic Extension 下插入此行後,

         並重新啟動apache server

         extension=memcache.so

           
shell> php -i | grep -i 'memcache'    
 
          #
利用此指令查驗mechache 是否已載入


          

       shell> php -i | grep -i 'memcache'   
  
        
memcache support => enabled     # PHP對memcache 的support 已啟動

       

        最後我們測試Memcached 是否正常運行,編輯Test.php,並且執行

          vi  test.php

        <?php
         $memcache = new Memcache;
        $memcache->connect('127.0.0.1', 11211);   #port號請修改成自己設定的port
        $stats = $memcache->getStats();
        foreach ($stats as $key => $val) {
        echo "$key : $val\n";
        }
        ?>

      

    LAB參考資料

http://blog.xuite.net/chingwei/blog/21360187 

http://blog.xuite.net/chingwei/blog/21360187

      

arrow
arrow
    全站熱搜

    終極.凱因斯 發表在 痞客邦 留言(0) 人氣()