PHP-FPM-Pool, PHP-Protokoll für langsame Ausführung, open_basedir, PHP-FPM-Prozessverwaltung

不言
Freigeben: 2023-03-24 07:54:02
Original
2278 Leute haben es durchsucht

Dieser Artikel stellt den Inhalt von PHP-FPM-Pool, PHP-Slow-Execution-Log, Open_basedir und PHP-FPM-Prozessverwaltung vor. Jetzt kann ich ihn mit Ihnen teilen.

Pool-Konfiguration von PHP-FPM


In Nginx können mehrere virtuelle Maschinen geöffnet werden, und alle benötigen PHP, um Dienste bereitzustellen, um sicherzustellen, dass jede Unterschiedliche Leistung der virtuellen Maschine, mehrere PHP-FPM-Pool-Dienste können aktiviert werden. Jeder Pool bedient einen Standort.

Methode 1:
Inhalt in /usr/local/php-fpm/etc/php-fpm.conf hinzufügen:

//两个模块命名为不同名字,监听的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
Nach dem Login kopieren

Pool verwenden:

[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
Nach dem Login kopieren

Eine Definition:

[root@shuai-01 vhost]# vi test.com.conf
Nach dem Login kopieren

PHP-FPM-Pool, PHP-Protokoll für langsame Ausführung, open_basedir, PHP-FPM-Prozessverwaltung

Eine Definition ist:

[root@shuai-01 vhost]# vi aaa.com.conf
Nach dem Login kopieren

PHP-FPM-Pool, PHP-Protokoll für langsame Ausführung, open_basedir, PHP-FPM-Prozessverwaltung

Methode 2:
Die erste Methode scheint unordentlich. Es kann der Include-Anweisung beim Hinzufügen einer virtuellen Maschine in Nginx ähneln.

Inhalt in /usr/local/php-fpm/etc/php-fpm.conf hinzufügen:
include = etc/php-fpm.d/*.conf
Dann löschen Sie die folgende Konfiguration Stellungnahme.

 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都出现了
Nach dem Login kopieren

Protokoll der langsamen Ausführung

php-fpm verfügt über eine sehr nützliche Funktion, nämlich das Protokoll der langsamen Ausführung. Es kann sehr effektiv zur Diagnose von Systemproblemen eingesetzt werden. Vor allem, wenn der Systemzugriff langsam ist.

vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
//Folgenden Inhalt hinzufügen
request_slowlog_timeout = 1 //Anweisungen aufzeichnen, die länger als ausgeführt wurden Eine Sekunde Komm runter, in einer Produktionsumgebung dauert es normalerweise 2 Sekunden, hier zu schreiben
slowlog = /usr/local/php-fpm/var/log/www-slow.log //Protokollspeicherverzeichnis

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  //测试
Nach dem Login kopieren

Test Wenn ein 502-Fehler auftritt, unterscheidet sich die im Pool überwachte *.sock von der Hauptkonfigurationsdatei.

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
Nach dem Login kopieren

当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
Nach dem Login kopieren

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

[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
Nach dem Login kopieren

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/
Nach dem Login kopieren

 相关推荐:

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

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

PHP 配置文件中open_basedir选项作用

          

Das obige ist der detaillierte Inhalt vonPHP-FPM-Pool, PHP-Protokoll für langsame Ausführung, open_basedir, PHP-FPM-Prozessverwaltung. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!