tbwshc

          PHP-FPM高負載的解決辦法

          這里只是介紹了php-fpm的優化方法的,但一般情況下和nginx組合使用的時候,單獨優化其中一項的話,作用不是特別的大,同時還需要對nginx進行優化.nginx的做法方法參考:http://blog.haohtml.com/archives/6213.上面的優化前和優化后的圖,看得出前后差距還是特別的大的.

          導致nginx 502 bad gateway的PHP-CGI(FASTCGI)

          NGINX頻爆502 BAD GATEWAY的錯誤,看了網上的教程,仍沒有徹底解決。

          目前我總結的解決502 BAD GATEWAY的方式有:

          1.視服務器的性能,在php-fmp.conf里增加max_children的值,我目前用的15.

          2.用reload參數定時重載php-fpm。這個主要原因是php腳本執行時間過長造成的,重載php-fpm能杜絕這個問題。如何徹底解決php-cgi腳本占用大量內存從而導致502錯誤的產生還值得進一步探討,目前該做法不失為一種好辦法。

          具體的做法是,用crontab讓php-fpm平滑重啟,從而不影響PHP腳本的tb運行。

          */10 * * * * /usr/local/php/sbin/php-fpm reload

          =================== 優化設置 =========================


          When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )

          如果您高負載網站使用PHP-FPM管理FastCGI,這些技巧也許對您有用:)

          1. Compile PHP’s modules as less as possible, the simple the best (fast);

          1.盡量少安裝PHP模塊,最簡單是最好(快)的

          2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);

          2.把您的PHP FastCGI子進程數調到100或以上,在4G內存的服務器上200就可以

          注:我的1g測試機,開64個是最好的,建議使用壓力測試獲取最佳值

          3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;

          3.使用socket連接FastCGI,linux操作系統可以放在 /dev/shm中

          注:在php-fpm.cnf里設置<value name=”listen_address”>/tmp/nginx.socket</value>就可以通過socket連接FastCGI了,/dev/shm是內存文件系統,放在內存中肯定會快了.記得這時也要在nginx里的配置里進行修改,保持一致.

          location ~ .*\.(php|php5)?$
          {
          #將Nginx與FastCGI的通信方式由TCP改為Unix Socket。TCP在高并發訪問下比Unix Socket穩定,但Unix Socket速度要比TCP快。
          fastcgi_pass  unix:/tmp/php-cgi.sock;
          #fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          include fcgi.conf;
          }

          4. Increase Linux “max open files”, using the following command (must be root):

          # echo ‘ulimit -HSn 65536′ >> /etc/profile
           # echo ‘ulimit -HSn 65536 >> /etc/rc.local
           # source /etc/profile 


          4.調高linux內核打開文件數量,可以使用這些命令(必須是root帳號)

          echo ‘ulimit -HSn 65536′ >> /etc/profile
           echo ‘ulimit -HSn 65536′ >> /etc/rc.local
           source /etc/profile 


          注:我是修改/etc/rc.local,加入ulimit -SHn 51200的

          5. Increase PHP-FPM open file description rlimit:

          # vi /path/to/php-fpm.conf
           Find “<value name=”rlimit_files”>1024</value>”
           Change 1024 to 4096 or higher number.
           Restart PHP-FPM.


          5. 增加 PHP-FPM 打開文件描述符的限制:

          # vi /path/to/php-fpm.conf
           找到“<value name=”rlimit_files”>1024</value>”
           把1024 更改為 4096 或者更高.
          重啟 PHP-FPM.


          6. Using PHP code accelerator, e.g eAccelerator, XCache. And set “cache_dir” to /dev/shm on Linux.
          6.使用php代碼加速器,例如 eAccelerator, XCache.在linux平臺上可以把`cache_dir`指向 /dev/shm

          至于其它的優化見李宴的bltbog一篇文章:http://blog.s135.com/post/375/

          This entry was posted in js框架 and tagged nginx, php-fpm by admin. Bookmark the permalink.

          One thought on “PHP-FPM高負載的解決辦法

          posted on 2012-08-16 14:48 chen11-1 閱讀(11743) 評論(0)  編輯  收藏

          主站蜘蛛池模板: 镇沅| 隆回县| 广水市| 新乡市| 兰溪市| 阳曲县| 林州市| 会理县| 东兴市| 九龙县| 封开县| 宜君县| 清镇市| 尉犁县| 满洲里市| 阜南县| 天津市| 上犹县| 铜山县| 肃南| 元谋县| 孙吴县| 阿图什市| 资溪县| 贵南县| 平舆县| 南投市| 南康市| 张掖市| 余江县| 宁明县| 长阳| 赣榆县| 石城县| 新乡市| 遂溪县| 连平县| 新化县| 忻城县| 大余县| 洮南市|