This article introduces the content of php-fpm pool, PHP slow execution log, open_basedir, and php-fpm process management. It has certain reference value. Now I share it with you. Friends in need can refer to it
Multiple virtual machines can be opened in nginx, and they all require PHP to provide services, so in order to ensure that each different virtual machine Performance, multiple php-fpm pool services can be enabled. Each pool serves one site.
Method 1:
Add content in /usr/local/php-fpm/etc/php-fpm.conf:
//两个模块命名为不同名字,监听的socket名字也不一样。在vhost相应的conf的中设置对应路径即可。 [www] listen = /tmp/www.sock listen.mode=666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 [shuai。com] listen = /tmp/shuai.sock listen.mode=666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 /usr/local/php-fpm/sbin/php-fpm -t //验证配置是否正确 service php-fpm restart //重启 [root@shuai-01 etc]# ps aux |grep php-fpm root 5854 1.2 0.4 227212 4972 ? Ss 01:41 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf) php-fpm 5855 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5856 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5857 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5858 0.0 0.4 227152 4708 ? S 01:41 0:00 php-fpm: pool www php-fpm 5859 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5860 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5861 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5862 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool www php-fpm 5863 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5864 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5865 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5866 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5867 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5868 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5869 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5870 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5871 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5872 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5873 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5874 0.0 0.4 227152 4716 ? S 01:41 0:00 php-fpm: pool www php-fpm 5875 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5876 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5877 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5878 0.0 0.4 227152 4712 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5879 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5880 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5881 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5882 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5883 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5884 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5885 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5886 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5887 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5888 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5889 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5890 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5891 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5892 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5893 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com php-fpm 5894 0.0 0.4 227152 4720 ? S 01:41 0:00 php-fpm: pool shuai.com root 5897 0.0 0.0 112684 976 pts/0 S+ 01:42 0:00 grep --color=auto php-fpm
Use pool:
[root@shuai-01 etc]# cd /usr/local/nginx/conf/vhost/ [root@shuai-01 vhost]# ls aaa.com.conf ld.conf proxy.conf ssl.conf test.com.conf
One definition:
[root@shuai-01 vhost]# vi test.com.conf
[root@shuai-01 vhost]# vi aaa.com.conf
The first method appears Not tidy enough. It can be similar to the include statement when adding a virtual machine in nginx.
include = etc/php-fpm.d/*.conf
Then delete the following configuration statement.
mkdir /usr/local/php-fpm/etc/php-fpm.d/ cd /usr/local/php-fpm/etc/php-fpm.d/ vim www.conf //内容如下 [www] listen = /tmp/www.sock listen.mode=666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 vim aming.conf //内容如下 [aming] listen = /tmp/aming.sock //监听的sock名字互不相同 listen.mode=666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024 //检查vhost的conf文件,相应的更改监听sock /usr/local/php-fpm/sbin/php-fpm -t //验证配置是否正确 service php-fpm restart //重启 ps aux |grep php-fpm //发现aming和www都出现了
//Add the following content
request_slowlog_timeout = 1 //Record statements executed for more than one second Come down, in the production environment, it usually takes 2 seconds to write here
slowlog = /usr/local/php-fpm/var/log/www-slow.log //Log storage directory
vim /data/wwwroot/test.com/sleep.php //写入如下内容 <?php echo "test slow log"; sleep(2); echo "done"; ?> [root@cent01 vhost]# curl -x127.0.0.1:80 test.com/sleep.php //测试
test slow logdone [root@cent01 vhost]# cat /usr/local/php-fpm/var/log/www-slow.log //慢日志提示第三行花费的时间太多 [16-Nov-2017 20:20:39] [pool www] pid 14208 script_filename = /data/nginx/test.com/sleep.php [0x00007f630f62f270] sleep() /data/nginx/test.com/sleep.php:3
当php文件遇到错误时,查错可以在/etc/init.d/php-fpm.ini 文件中打开display_error功能,这样错误就能直接在浏览器上显示。
open_basedir如果在php.ini中定义就不合适,在pool中定义刚刚好,在Apache中定义在虚拟主机配置文件。
可以直接在/usr/local/php-fpm/etc/php-fpm.d/www.conf中添加如下语句:
php_admin_value[open_basedir]=/data/nginx/aming.com:/tmp/
配置完成后重启服务 service php-fpm restart 或者 /etc/init.d/php-fpm restart
其中路径需要配置正确。否则会报错。
将配置文件改为如下几行。
[root@shuai-01 php-fpm.d]# vi /usr/local/php-fpm/etc/php.ini error_log=/usr/local/php-fpm/var/log/php_errors.log error_reporting=E_ALL display_errors = Off log_errors = On
创建一个存放错误日志的文件
[root@shuai-01 php-fpm.d]# touch /usr/local/php-fpm/var/log/php_errors.log [root@shuai-01 php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_errors.log
[root@shuai-01 php-fpm.d]# cat www.conf [www] listen = /tmp/www.sock listen.mode=666 user = php-fpm group = php-fpm pm = dynamic //动态的 ;pm = static pm.max_children = 50 //最大子进程50个 pm.start_servers = 20 // 启动的时候20个 pm.min_spare_servers = 5 //空闲时,最少有5个 pm.max_spare_servers = 35 //空闲时,最大有35个 pm.max_requests = 500 // 一个进程最多的请求数 rlimit_files = 1024 request_slowlog_timeout = 1 slowlog = /usr/local/php-fpm/var/log/www-slow.log php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
相关推荐:
The above is the detailed content of php-fpm pool, PHP slow execution log, open_basedir, php-fpm process management. For more information, please follow other related articles on the PHP Chinese website!