Apache 跟 PHP的效能調校

ㄚ琪今天試著調校Apache跟PHP,兩個要綁在一起說明,主要就是因為PHP只能在Apache的apache2-mpm-prefork模式下使用,所以這樣子也會連帶有影響到Apache的效能調校,今天主要參考的文章來自PHP Everywhere.Tuning Apache and PHP for Speed on Unix,不知會不會有版本上的差異,不過我們還是先行來試試,這樣子各位在工作達人上的瀏覽可能會更好,當然如果有錢砸在頻寬上那就更讚了,不過這還只是個夢而已。

1.設定php.ini

output_handler = ob_gzhandler

ㄚ琪另外參考目前檔案上的備註:

; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to “mb_output_handler”, character
; encoding will be transparently converted to the specified encoding.
; Setting any output handler automatically turns on output buffering.
; Note: People who wrote portable scripts should not depend on this ini
; directive. Instead, explicitly set the output handler using ob_start().
; Using this ini directive may cause problems unless you know what script
; is doing.
; Note: You cannot use both “mb_output_handler” with “ob_iconv_handler”
; and you cannot use both “ob_gzhandler” and “zlib.output_compression”.
; Note: output_handler must be empty if this is set ‘On’ !!!!
; Instead you must use zlib.output_handler.
; http://php.net/output-handler

這裡有提到”ob_gzhandler” 跟 “zlib.output_compression”不可以同時使用,ㄚ琪查過目前zlib.output_compression=Off,所以應該沒有關係。

作者提到這樣地的設定,可以節省2~3秒左右。

2.在php.ini設定

session.save_handler=mm

ㄚ琪查自己的目前設定為session.save_handler = files

先備註起來,觀察測試。

重新啟動之後,工作達人的Google Page Speed突然從87分升到99分,傑克太神奇了吧,不過也怕是假象,先拍照存證紀念一下好了。

3.作者建議不要跑X-Windows,ㄚ琪也贊成,改天機子搬回桃園再來砍X-Windows。

4.以前有常用的hdparm,但是現行的SATA硬碟好像不適用,這一個ㄚ琪先保留,等求證後再上線測試。

其餘的ㄚ琪就先不試了,因為裡頭很多的連結大都失效,不參考了,先維持這樣。

2012/05/22註:output_handler = ob_gzhandler會造成WordPress瀏覽產生亂碼,目前已拿掉,感謝Hannah的提醒,她目前在成大研究所唸書。

修改回來後的分數:

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *