PHP-FPM实现性能优化
简介: PHP-FPM 是一个 PHP FastCGI 管理器,一般 Nginx 上面跑 PHP 程序都会将 PHP 程序丢给 PHP-FPM 来解析。好了,就这样! PHP 5.4 开始集成了 PHP-FPM ,也就是说编译 PHP 时,只要 --enable-fpm 就装好了 PHP-FPM 。 一、安装 PHP-FPM ./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
## 看到上面这堆参数了没有,这是在编译 PHP ,其中有一个参数是 --enable-fpm 没错,这就是启用 PHP-FPM 扩展。 make; make install
二、配置 PHP-FPM 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 # 复制一份配置文件
shell > vim php-fpm.conf
[global] pid = run/php-fpm.pid # PID [www] # 进程池 user = nginx # 以 nginx 身份运行 listen = 127.0.0.1:9000 # 监听本机的 9000 端口 ;listen = /dev/shm/php-cgi.sock; # 监听 UNIX SOCKET ,并把 SOCKET 放在了内存空间中,速度更快 ( Nginx 也要相应修改 )! ;listen.owner = nginx # UNIX SOCKET 的权限 pm = dynamic # 创建进程的方式,动态创建 pm.status_path = /php_status # PHP-FPM 状态监控 ( Nginx 要设置访问权限 ) shell > service php-fpm start 三、监控 PHP-FPM vim /usr/local/nginx/conf/nginx.conf
location ~ /php_status { # 创建一个单独的 server 或直接在 server {} 中加入配置 access_log off; allow 127.0.0.1; fastcgi_pass 127.0.0.1:9000; # 如果是 UNIX SOCKET 的方式,要类似这样写: fastcgi_pass unix:/dev/shm/php-cgi.sock; shell > kill -HUP shell > curl http://127.0.0.1/php_status # 访问该路径得到如下数据 shell > curl http://127.0.0.1/php_status # 这里有多种参数供选择,例如: http://127.0.0.1/php_status?html 、?json 、?xml 、?full # 我想,用 python 脚本用做个监控,?json 格式是最好不过了吧! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |