Forked from diyism/在top里看到某个php进程占用cpu很高想知道对应的request url
Created
August 31, 2018 02:34
-
-
Save rainly/f11d51810abb2a34fe99234d513b0ee2 to your computer and use it in GitHub Desktop.
在top里看到某个php进程占用cpu很高想知道对应的request url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
在top里看到某个php进程占用cpu很高想知道对应的request url: | |
php 5.3以上有fpm status page功能(http://php.net/manual/en/install.fpm.configuration.php#pm.status-path), 但是从网页访问的, | |
改用cgi-fcgi从命令行访问比较安全方便, cgi-fcgi就是cgi(nginx) to fcgi(php5-fpm)的意思 | |
sudo vi /etc/php5/fpm/pool.d/www.conf | |
#解除注释 pm.status_path = /status | |
sudo service php5-fpm restart | |
sudo apt-get install libfcgi0ldbl #centos是yum install fcgi (先sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 及 sudo yum upgrade ca-certificates --disablerepo=epel) | |
sudo SCRIPT_FILENAME=. SCRIPT_NAME=/status QUERY_STRING="full" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | grep -A7 <pid> | |
#就可以看到对应pid的php-fpm进程的request URI了 | |
测试其他url(SCRIPT_NAME相当于rewrite过后当前uri, REQUEST_URI即原始uri): | |
sudo SERVER_NAME=test.com SCRIPT_FILENAME=/var/workspace/www/index.php SCRIPT_NAME=/index.php/controller1 REQUEST_URI="/controller1?name=hello" QUERY_STRING="name=hello" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | |
平均最高cpu的php进程的url: | |
sudo SCRIPT_FILENAME=. SCRIPT_NAME=/status QUERY_STRING="full" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | grep -A7 $(ps aux | grep -v grep | grep www-data | sort -k3nr | head -n 1 | awk '{print $2}') | |
请求时间大于8秒的php进程的url: | |
sudo SCRIPT_FILENAME=. SCRIPT_NAME=/status QUERY_STRING="full" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | awk '$2=="duration:" && $3>8000000 {c=10} c&&c--' | |
请求时间大于8秒的php进程的总数: | |
sudo SCRIPT_FILENAME=. SCRIPT_NAME=/status QUERY_STRING="full" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | awk '$2=="duration:" && $3>8000000 {c=1} c&&c--' | wc -l | |
汇总信息(比如正在运行的php进程数等): | |
sudo SCRIPT_FILENAME=index.php SCRIPT_NAME=/status REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment