Table of Contents
Pool configuration of php-fpm
open_basedir
php-fpm进程管理
Home Backend Development PHP Tutorial php-fpm pool, PHP slow execution log, open_basedir, php-fpm process management

php-fpm pool, PHP slow execution log, open_basedir, php-fpm process management

Apr 17, 2018 am 11:33 AM
open php-fpm pool

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

Pool configuration of php-fpm


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
Copy after login

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
Copy after login

One definition:

[root@shuai-01 vhost]# vi test.com.conf
Copy after login

php-fpm pool, PHP slow execution log, open_basedir, php-fpm process management

## One definition:

[root@shuai-01 vhost]# vi aaa.com.conf
Copy after login

php-fpm pool, PHP slow execution log, open_basedir, php-fpm process management

Method 2:

The first method appears Not tidy enough. It can be similar to the include statement when adding a virtual machine in nginx.

Add content in /usr/local/php-fpm/etc/php-fpm.conf:

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都出现了
Copy after login

Slow execution log

php-fpm has a very useful function, which is the slow execution log. It can be used very effectively to diagnose system problems. Especially when system access is slow.

vim /usr/local/php-fpm/etc/php-fpm.d/www.conf

//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  //测试
Copy after login

During testing A 502 error occurs, and the *.sock monitored in the pool is different from the main configuration file.

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
Copy after login

当php文件遇到错误时,查错可以在/etc/init.d/php-fpm.ini 文件中打开display_error功能,这样错误就能直接在浏览器上显示。

open_basedir

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
Copy after login

创建一个存放错误日志的文件

[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
Copy after login

php-fpm进程管理

[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/
Copy after login

 相关推荐:

php配置php-fpm启动参数及配置详

详解open_basedir 配置项的文件权限问题

PHP 配置文件中open_basedir选项作用

          

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use php-fpm for high-performance tuning How to use php-fpm for high-performance tuning Jul 08, 2023 am 11:30 AM

How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

How to use PHP-FPM optimization to improve the performance of PrestaShop applications How to use PHP-FPM optimization to improve the performance of PrestaShop applications Oct 05, 2023 pm 12:33 PM

How to use PHP-FPM optimization to improve the performance of PrestaShop applications. With the rapid development of the e-commerce industry, PrestaShop has become the e-commerce platform chosen by many merchants. However, as the size of the store increases and the number of visits increases, the PrestaShop application may encounter performance bottlenecks. In order to improve the performance of the PrestaShop application, a common method is to use PHP-FPM to optimize and improve the application's processing capabilities. PHP-FPM (FastCGI

How to improve the performance of your WooCommerce application using PHP-FPM optimization How to improve the performance of your WooCommerce application using PHP-FPM optimization Oct 05, 2023 am 08:24 AM

How to Improve the Performance of WooCommerce Applications Using PHP-FPM Optimization Overview WooCommerce is a very popular e-commerce plugin for creating and managing online stores on WordPress websites. However, as your store grows and traffic increases, WooCommerce apps can become slow and unstable. To solve this problem, we can use PHP-FPM to optimize and improve the performance of WooCommerce applications. What is PHP-FP

Use php-fpm connection pool to improve database access performance Use php-fpm connection pool to improve database access performance Jul 07, 2023 am 09:24 AM

Overview of using php-fpm connection pool to improve database access performance: In web development, database access is one of the most frequent and time-consuming operations. The traditional method is to create a new database connection for each database operation and then close the connection after use. This method will cause frequent establishment and closing of database connections, increasing system overhead. In order to solve this problem, you can use php-fpm connection pool technology to improve database access performance. Principle of connection pool: Connection pool is a caching technology that combines a certain number of databases

Detailed explanation of php-fpm tuning method Detailed explanation of php-fpm tuning method Jul 08, 2023 pm 04:31 PM

PHP-FPM is a commonly used PHP process manager used to provide better PHP performance and stability. However, in a high-load environment, the default configuration of PHP-FPM may not meet the needs, so we need to tune it. This article will introduce the tuning method of PHP-FPM in detail and give some code examples. 1. Increase the number of processes. By default, PHP-FPM only starts a small number of processes to handle requests. In a high-load environment, we can improve the concurrency of PHP-FPM by increasing the number of processes

How to use PHP-FPM optimization to improve the performance of Phalcon applications How to use PHP-FPM optimization to improve the performance of Phalcon applications Oct 05, 2023 pm 01:54 PM

How to use PHP-FPM to optimize and improve the performance of Phalcon applications. Introduction: Phalcon is a high-performance PHP framework. Combining with PHP-FPM can further improve the performance of applications. This article will introduce how to use PHP-FPM to optimize the performance of Phalcon applications and provide specific code examples. 1. What is PHP-FPMPHP-FPM (PHPFastCGIProcessManager) is a PHP process independent of the web server

What to do if ubuntu doesn't have php-fpm What to do if ubuntu doesn't have php-fpm Feb 03, 2023 am 10:51 AM

Solution for Ubuntu without php-fpm: 1. Add the source address of PHP by executing the "sudo apt-get" command; 2. Check whether there is a php7 package; 3. Install PHP by executing the "sudo apt-get install" command; 4. , modify the configuration to listen on port 9000 to handle nginx requests; 5. Start "php7.2-fpm" through "sudo service php7.2-fpm start".

PHP-FPM performance improvement strategies and practice guide PHP-FPM performance improvement strategies and practice guide Oct 05, 2023 pm 03:55 PM

Introduction to PHP-FPM Performance Improvement Strategies and Practice Guide: With the rapid development of the Internet and the increasing number of website visits, it is particularly important to improve the performance of PHP applications. PHPFastCGIProcessManager (PHP-FPM) is a commonly used PHP process manager that can improve the performance of PHP applications through a series of strategies and practices. This article will introduce some PHP-FPM performance improvement strategies, combined with specific code examples, to help readers better understand

See all articles