国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP-FPM實現(xiàn)性能優(yōu)化

Original 2017-01-06 10:28:10 402
abstract:本文給大家介紹的是通過php-fpm實現(xiàn)性能優(yōu)化的配置方法以及注意事項簡介:PHP-FPM 是一個 PHP FastCGI 管理器,一般 Nginx 上面跑 PHP 程序都會將 PHP 程序丟給 PHP-FPM 來解析。好了,就這樣!PHP 5.4 開始集成了 PHP-FPM ,也就是說編譯 PHP 時,只要 --enable-fpm 就裝好了 PHP-FPM 。一、安裝 PHP-FPMshell

本文給大家介紹的是通過php-fpm實現(xiàn)性能優(yōu)化的配置方法以及注意事項

簡介:

PHP-FPM 是一個 PHP FastCGI 管理器,一般 Nginx 上面跑 PHP 程序都會將 PHP 程序丟給 PHP-FPM 來解析。好了,就這樣!

PHP 5.4 開始集成了 PHP-FPM ,也就是說編譯 PHP 時,只要 --enable-fpm 就裝好了 PHP-FPM 。

一、安裝 PHP-FPM

shell > ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-gd --with-xsl --with-bz2 \
--with-zlib --with-curl --with-pear --without-iconv --with-mcrypt \
--with-gettext --with-openssl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir \
--with-libdir=lib64 --enable-ftp --enable-fpm --enable-opcache --enable-exif --enable-soap --enable-bcmath --enable-calendar \
--enable-sockets --enable-mbstring --enable-gd-native-ttf --disable-rpath --disable-debug

## 看到上面這堆參數(shù)了沒有,這是在編譯 PHP ,其中有一個參數(shù)是 --enable-fpm 沒錯,這就是啟用 PHP-FPM 擴展。

shell > make; make install

二、配置 PHP-FPM

shell > cp /usr/local/src/php-5.6.17/php.ini-production /usr/local/php/php.ini # 這是 PHP 的配置文件
shell > cp /usr/local/src/php-5.6.17/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm # 這是 PHP-FPM 的啟動腳本
shell > cd /usr/local/php/etc/
shell > cp php-fpm.conf.default php-fpm.conf # 復(fù)制一份配置文件
shell > vim php-fpm.conf

 

[global]

pid = run/php-fpm.pid # PID

rlimit_files = 65535 # 打開文件數(shù)限制

[www] # 進程池 

user = nginx # 以 nginx 身份運行

group = nginx 

listen = 127.0.0.1:9000 # 監(jiān)聽本機的 9000 端口 

;listen = /dev/shm/php-cgi.sock; # 監(jiān)聽 UNIX SOCKET ,并把 SOCKET 放在了內(nèi)存空間中,速度更快 ( Nginx 也要相應(yīng)修改 )!

;listen.backlog = 10240 # UNIX SOCKET 的方式高并發(fā)下有點不穩(wěn)定,該參數(shù)用來緩解 ( SOCKET 等待隊列長度 )

;listen.owner = nginx # UNIX SOCKET 的權(quán)限

;listen.group = nginx

;listen.mode = 0660


pm = dynamic # 創(chuàng)建進程的方式,動態(tài)創(chuàng)建

pm.max_children = 32 # 最大進程數(shù) ( 不能只看內(nèi)存來創(chuàng)建,要看具體使用率,有時內(nèi)存足夠,進程數(shù)大多時,導(dǎo)致 CPU 頻繁上下文切換,負(fù)載會很高 )

pm.start_servers = 5 # 初始進程數(shù)

pm.min_spare_servers = 5 # 最小空閑進程數(shù)

pm.max_spare_servers = 10 # 最大空閑進程數(shù) 

pm.status_path = /php_status # PHP-FPM 狀態(tài)監(jiān)控 ( Nginx 要設(shè)置訪問權(quán)限 ) 

shell > service php-fpm start   

三、監(jiān)控 PHP-FPM

shell > vim /usr/local/nginx/conf/nginx.conf
 
location ~ /php_status { # 創(chuàng)建一個單獨的 server 或直接在 server {} 中加入配置
 
  access_log off;
 
  allow 127.0.0.1;
  allow 36.110.41.194; # 做好權(quán)限
  deny all;
 
  fastcgi_pass 127.0.0.1:9000; # 如果是 UNIX SOCKET 的方式,要類似這樣寫: fastcgi_pass unix:/dev/shm/php-cgi.sock;
  fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
  include fastcgi_params;
}

 

shell > kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

 

shell > curl http://127.0.0.1/php_status # 訪問該路徑得到如下數(shù)據(jù)

pool: www               # 進程池名稱

process manager: dynamic        # 進程管理方式

start time: 22/Jan/2016:15:49:00 +0800 # 啟動時間

start since: 375            # 運行時長

accepted conn: 7            # 當(dāng)前進程池接受的請求數(shù)

listen queue: 0            # 請求等待隊列,如果不為 0 ,意味著 FPM 進程不足,需要增加

max listen queue: 0          # 最大等待隊列數(shù)量

listen queue len: 1024         # SOCKET 等待隊列長度

idle processes: 4           # 空閑進程數(shù)

active processes: 1          # 活躍的進程數(shù)

total processes: 5           # 總進程數(shù)

max active processes: 1        # 最大活躍進程數(shù)

max children reached: 0        # 達(dá)到最大進程數(shù)的次數(shù),如果不為 0 ,意味著最大進程數(shù)不足,需要增加

slow requests: 0            # 慢請求數(shù)量,需要設(shè)置 slow log

 

shell > curl http://127.0.0.1/php_status # 這里有多種參數(shù)供選擇,例如: http://127.0.0.1/php_status?html 、?json 、?xml 、?full

   

# 我想,用 python 腳本用做個監(jiān)控,?json 格式是最好不過了吧!


Release Notes

Popular Entries