PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM process Management

Source: Internet
Author: User
This article introduces the contents of the PHP-FPM pool, php slow execution log, Open_basedir, PHP-FPM process Management, has a certain reference value, now share to everyone, the need for friends can refer to

Pool configuration for PHP-FPM


Nginx can open more than one virtual machine, they all need PHP to provide services, so in order to ensure the performance of each different virtual machine, you can open multiple PHP-FPM pool service. Each pool serves one site.

Method 1:
Add content to/usr/local/php-fpm/etc/php-fpm.conf:

Two modules are named with different names, and the names of the sockets that are monitored are not the same. Set the corresponding path in the vhost corresponding Conf.  [Www]listen =/tmp/www.socklisten.mode=666user = Php-fpmgroup = PHP-FPMPM = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024[shuai. Com]listen =/tmp/shuai.socklisten.mode=666user = Php-fpmgroup = PHP-FPMPM = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024/usr/local/php-fpm/sbin/ PHP-FPM-T//Verify that the configuration is correct service php-fpm restart//restart [root@shuai-01 etc]# PS aux |grep php-fpmroot 5854 1.2 0.4 2272        12 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 wwwphp-fpm 5856 0.0 0.4 227152 4708?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5857 0.0 0.4 227152 4708? S 01:41 0:00 php-fpm:pool wwwphp-fpm 5858 0.0  0.4 227152 4708?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5859 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5860 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5861 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5862 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5863 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5864 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5865 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5866 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5867 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5868 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5869 0.0 0.4 227152 4716? S 01:41 0:00 php-fpm:pool wwwphp-fpm 5870 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5871 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5872 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5873 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5874 0.0 0.4 227152 4716?        S 01:41 0:00 php-fpm:pool wwwphp-fpm 5875 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5876 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5877 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5878 0.0 0.4 227152 4712?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5879 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5880 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5881 0.0 0.4 227152 4720? S 01:41 0:00 php-fpm:Pool shuai.comphp-fpm 5882 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5883 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5884 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5885 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5886 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5887 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5888 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5889 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5890 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5891 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5892 0.0 0.4 227152 4720? S 01:41 0:00 Php-fpm:pool shuai.comphp-fpm    5893 0.0 0.4 227152 4720?        S 01:41 0:00 php-fpm:pool shuai.comphp-fpm 5894 0.0 0.4 227152 4720? S 01:41 0:00 php-fpm:pool shuai.comroot 5897 0.0 0.0 112684 976 pts/0 s+ 01:42 0:00 grep--color=au To PHP-FPM

Using pool:

[root@shuai-01 etc]# cd/usr/local/nginx/conf/vhost/[root@shuai-01 vhost]# lsaaa.com.conf  ld.conf  proxy.conf  ssl.conf  test.com.conf

A definition:

[Root@shuai-01 vhost]# VI test.com.conf

One is defined as:

[Root@shuai-01 vhost]# VI aaa.com.conf

Method 2:
The first method appears to be not neat enough. Can resemble the include statement when Nginx adds a virtual machine.

Add content to/usr/local/php-fpm/etc/php-fpm.conf:
Include = etc/php-fpm.d/*.conf
Then remove 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//content is as follows [Www]listen =/tmp/ Www.socklisten.mode=666user = Php-fpmgroup = PHP-FPMPM = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_ Servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024vim aming.conf//content is as follows [Aming]listen =/tmp/amin G.sock  //Listener sock names are different listen.mode=666user = Php-fpmgroup = PHP-FPMPM = Dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024//Check vhost conf file, The corresponding changes are monitored sock/usr/local/php-fpm/sbin/php-fpm-t  //Verify that the configuration is correct service php-fpm restart  //restart PS aux |grep php-fpm  //Found aming and www all appeared

Slow execution Log

PHP-FPM has a very useful function, which is to slow down the execution log. It can be very effective to diagnose the problem of the system where. Especially when the system is slow to access.

Vim/usr/local/php-fpm/etc/php-fpm.d/www.conf
Add the following:
Request_slowlog_timeout = 1//execute more than one second of statement recording down, production environment, here generally write 2 seconds
Slowlog =/usr/local/php-fpm/var/log/www-slow.log//Log storage directory

vim/data/wwwroot/test.com/sleep.php//writes the following <?php echo "Test slow Log"; Sleep (2); echo "Done"; >[root@cent01 vhost]# curl-x127.0.0.1:80 test.com/sleep.php  //test

A 502 error occurred during the test, and the *.sock in the pool was in the main configuration file.

Test slow logdone[root@cent01 vhost]# cat/usr/local/php-fpm/var/log/www-slow.log  //Slow log tip the third line takes too much time [16-nov-2017 20:20:39]  [pool www] pid 14208script_filename =/data/nginx/test.com/sleep.php[0x00007f630f62f270] Sleep ()/data/ Nginx/test.com/sleep.php:3

When the php file encounters an error, the error can be found in the/etc/init.d/php-fpm.ini file to open the Display_error function, so that errors can be displayed directly on the browser.

Open_basedir

Open_basedir if defined in php.ini is not appropriate, defined in the pool just as well, defined in Apache in the virtual host configuration file.

You can add the following statement directly in the/usr/local/php-fpm/etc/php-fpm.d/www.conf:

php_admin_value[open_basedir]=/data/nginx/aming.com:/tmp/

Restart Service php-fpm Restart or/ETC/INIT.D/PHP-FPM after configuration is complete restart

Where the path needs to be configured correctly. Otherwise you will get an error.

Change the configuration file to the following lines.

[Root@shuai-01 php-fpm.d]# Vi/usr/local/php-fpm/etc/php.ini Error_log=/usr/local/php-fpm/var/log/php_ Errors.logerror_reporting=e_alldisplay_errors = Offlog_errors = On

Create a file that holds the error log

[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

PHP-FPM Process Management

[root@shuai-01 php-fpm.d]# Cat www.conf [Www]listen =/tmp/www.socklisten.mode=666user = Php-fpmgroup = PHP-FPMPM = dynamic//dynamically; PM = Staticpm.max_child ren = 50//MAX subprocess 50 pm.start_servers = 20//start at 20 pm.min_spare_servers = 5//idle, at least 5 Pm.max_spare_servers = 35//idle, Max There are 35 pm.max_requests = 500//The maximum number of requests for a process rlimit_files = 1024request_slowlog_timeout = 1 Slowlog =/usr/local/php-fpm/var/lo G/www-slow.log php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.