PHP-FPM pool, website slow execution log, define OPEN_BASEDIR, set PHP log, process management

Source: Internet
Author: User
Tags configuration php fpm php error php error log

PHP-FPM's Pool edit php-fpm configuration file
vim /usr/local/php-fpm/etc/php-fpm.conf

Increase

include = etc/php-fpm.d/*.conf

Delete

[www]listen = /tmp/php-fcgi.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
Create a Directory
mkdir /usr/local/php-fpm/etc/php-fpm.d/
Create a pool file
cd /usr/local/php-fpm/etc/php-fpm.d/vim www.conf

Increase

listen = /tmp/php-fcgi.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

Vim shu32.conf
Increase

[shu32]listen = /tmp/shu32.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
Set the default sock in the Web virtual file Settings socktest.com
vim /usr/local/nginx/conf/vhost/test.com.conf##解析php##    location ~ \.php$        {            include fastcgi_params;            fastcgi_pass unix:/tmp/php-fcgi.sock;            fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name;        }
aaa.com.conf set Sock to Shu32.sock
vim /usr/local/nginx/conf/vhost/aaa.com.conf##解析php##    location ~ \.php$        {            include fastcgi_params;            fastcgi_pass unix:/tmp/shu32.sock;            fastcgi_index index.php;            fastcgi_param SCRIPT_FILENAME /data/wwwroot/default$fastcgi_script_name;        }
Detection and entry into force

Both PHP-FPM and Nginx must be tested.

/usr/local/php-fpm/sbin/php-fpm -t/etc/init.d/php-fpm reload/usr/local/nginx/sbin/nginx -t/usr/local/nginx/sbin/nginx -s reload
Test

AAA and test use WWW and shu32 respectively

ps aux |grep php-fpm
Root 2001 0.0 0.4 227292 4988?        Ss 00:16 0:00 php-fpm:master process (/usr/local/php-fpm/etc/php-fpm.conf) PHP-FPM 2002 0.0 0.4 227232 4724?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2003 0.0 0.4 227232 4724?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2004 0.0 0.4 227232 4724?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2005 0.0 0.4 227232 4724?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2006 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2007 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2008 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2009 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2010 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2011 0.0 0.4 227232 4728? S 00:16 0:00 php-fpm:pool shu32php-fpm 2012 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2013 0.0 0.5 227232 5780?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2014 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2015 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2016 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2017 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2018 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2019 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2020 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2021 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool shu32php-fpm 2022 0.0 0.4 227232 4728?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2023 0.0 0.4 227232 4728? S 00:16 0:00 php-fpm:pool wwwphp-fpm 2024 0.0 0.5 227232 5508?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2025 0.0 0.5 227232 5736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2026 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2027 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2028 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2029 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2030 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2031 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2032 0.0 0.4 227232 4732?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2033 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2034 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2035 0.0 0.4 227232 4736?       S 00:16 0:00 php-fpm:pool wwwphp-fpm 2036 0.0 0.4 227232 4736? S 00:16 0:00 php-fpm:pool wwwphp-fpm 2037 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2038 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2039 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2040 0.0 0.4 227232 4736?        S 00:16 0:00 php-fpm:pool wwwphp-fpm 2041 0.0 0.4 227232 4736? S 00:16 0:00 Php-fpm:pool www
PHP-FPM Web site Slow execution log editing php-fpm separate configuration file
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf

Increase

request_slowlog_timeout = 1slowlog = /usr/local/php-fpm/var/log/www-slow.log
Detection and entry into force
/usr/local/php-fpm/sbin/php-fpm -t/etc/init.d/php-fpm reload
Create a test file

Let the Web pause for two seconds

vim /data/wwwroot/test.com/sleep.php<?phpecho "test slow log";sleep(2);echo "done";?>
Test
curl -x127.0.0.1:80 test.com/sleep.php

Access is two seconds before it's over.

View Logs

Prompt to access test.com/sleep.php slow reason in the third line of code

cat /usr/local/php-fpm/var/log/www-slow.log
[20-Mar-2018 00:57:28]  [pool www] pid 2469script_filename = /data/wwwroot/test.com/sleep.php[0x00007fb91fc38298] sleep() /data/wwwroot/test.com/sleep.php:3
PHP-FPM definition Open_basedir

The role of Open_basedir is to restrict PHP from being active in the specified directory.

Edit PHP-FPM configuration file
vim /usr/local/php-fpm/etc/php-fpm.d/www.conf

Add the following code

php_admin_value[open_basedir]=/data/wwwroot/test.com:/tmp/
Inspection effective
/usr/local/php-fpm/sbin/php-fpm -t/etc/init.d/php-fpm reload
Using Curl Testing

Success 200
Curl-x127.0.0.1:80 Test.com/admin.php-i

HTTP/1.1 200 OKServer: nginx/1.12.2Date: Mon, 19 Mar 2018 17:24:44 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.30
Configuration Error Directory

Change test.com to Wwtest.com

vim /usr/local/php-fpm/etc/php-fpm.d/www.confphp_admin_value[open_basedir]=/data/wwwroot/wwtest.com:/tmp/
Inspection effective
/usr/local/php-fpm/sbin/php-fpm -t/etc/init.d/php-fpm reload
Using Curl Testing

Curl-x127.0.0.1:80 Test.com/admin.php-i

HTTP/1.1 404 Not FoundServer: nginx/1.12.2Date: Mon, 19 Mar 2018 17:18:53 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveX-Powered-By: PHP/5.6.30
PHP error Log settings edit PHP-FPM configuration php.ini
vim /usr/local/php-fpm/etc/php.ini
log_errors = On  //开启错误日志记录error_log = /usr/local/php-fpm/var/log/php_errors.log    //指定错误日志目录error_reporting = E_ALL        //设置错误级别
Create a log file
touch /usr/local/php-fpm/var/log/php_errors.log chmod 777 /usr/local/php-fpm/var/log/php_errors.log
Inspection effective
/usr/local/php-fpm/sbin/php-fpm -t/etc/init.d/php-fpm reload
View Logs
cat /usr/local/php-fpm/var/log/php_errors.log
PHP-FPM Process Management
cat /usr/local/php-fpm/etc/php-fpm.d/www.conf
[www]listen = /tmp/php-fcgi.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 = 1024request_slowlog_timeout = 1slowlog = /usr/local/php-fpm/var/log/www-slow.logphp_admin_value[open_basedir]=/data/wwwroot/wtest.com:/tmp/

PM = dynamic/Active process management, also can be static
Pm.max_children = 50//maximum number of sub-processes, PS aux can be viewed
Pm.start_servers = 20//Number of processes that will start when the service is started
Pm.min_spare_servers = 5//Defines the minimum number of child processes in the idle period, and if this value is reached, the PHP-FPM service automatically derives the new child process.
Pm.max_spare_servers = 35//Defines the maximum number of child processes in the idle period, or, if higher than this value, to start cleaning up idle child processes.
Pm.max_requests = 500//defines the maximum number of requests processed by a child process, that is, a PHP-FPM child process can handle so many requests, and when this value is reached, it exits automatically.

PHP-FPM pool, website slow execution log, define OPEN_BASEDIR, set PHP log, process management

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.