PHP-CGI consuming 100% cpu - php

multiple php-cgi processes growing and crashing my cpu. Is there any configuration i need to do control this.
I am using apache(httpd) as a server.
top command result:
28278 random_user 20 0 418824 47092 13932 R 3.3 1.6 0:01.10 php-cgi
28335 random_user 20 0 410888 38856 13928 R 3.3 1.3 0:00.75 php-cgi
28340 random_user 20 0 410376 38156 13928 R 3.3 1.3 0:00.68 php-cgi
28342 random_user 20 0 410632 38132 13904 R 3.3 1.3 0:00.71 php-cgi
28395 random_user 20 0 410344 64892 13748 R 3.3 2.2 0:00.49 php-cgi
28456 random_user 20 0 401408 29420 13880 R 3.3 1.0 0:00.28 php-cgi
28474 random_user 20 0 400132 28176 13904 R 3.3 1.0 0:00.22 php-cgi
28494 random_user 20 0 399104 27056 13884 R 3.3 0.9 0:00.17 php-cgi
28513 random_user 20 0 398080 26100 13884 R 3.3 0.9 0:00.10 php-cgi
28221 random_user 20 0 421000 49744 13996 R 3.0 1.7 0:01.17 php-cgi
28239 random_user 20 0 419592 47604 13932 R 3.0 1.6 0:01.13 php-cgi
28249 random_user 20 0 419592 47616 13936 R 3.0 1.6 0:01.11 php-cgi
28277 random_user 20 0 419592 47340 13908 R 3.0 1.6 0:01.12 php-cgi
28282 random_user 20 0 417288 45504 13928 R 3.0 1.6 0:01.05 php-cgi
28304 random_user 20 0 415240 43420 13928 R 3.0 1.5 0:00.88 php-cgi
28309 random_user 20 0 413448 41584 13928 R 3.0 1.4 0:00.90 php-cgi
28311 random_user 20 0 413448 41480 13928 R 3.0 1.4 0:00.82 php-cgi
28312 random_user 20 0 412936 41052 13928 R 3.0 1.4 0:00.82 php-cgi

Related

PHP. 7.4 built-in server handle multiple requests?

https://www.php.net/manual/en/features.commandline.webserver.php
From 7.4+ onwards, I assume PHP built in server is capable of handling multiple incoming requests, up to and equal to the environment variable: PHP_CLI_SERVER_WORKERS
I have a web app which is composed of a couple dozen AJAX powered lists, on the first page load, using the built-in server it slows to a crawl, usually fails due to timeout in PHP scripts.
I read the above feature, added environment variable (PHP is a docker container), and shell'ed into my container, did a top/ps I can now see X number of PHP processes:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 722864 21932 14448 S 0.3 1.1 0:09.91 symfony
20 root 20 0 210892 48188 36544 S 0.0 2.4 0:00.79 php7.4
21 root 20 0 205676 33460 24500 S 0.0 1.6 0:00.22 php7.4
22 root 20 0 208212 40908 29640 S 0.0 2.0 0:00.42 php7.4
23 root 20 0 210644 42236 30836 S 0.0 2.1 0:00.61 php7.4
24 root 20 0 208764 40784 31176 S 0.0 2.0 0:01.14 php7.4
25 root 20 0 205804 33588 24508 S 0.0 1.6 0:00.22 php7.4
...
I am using Symfony to start a dev server, but no matter what I do none of the processes seem to be carrying any of the load? What am I missing?
I switched to the built-in PHP server about 2 years ago, from NGINX. It made my vagrant setup easier (now docker) but my performance took a hit, which I've dealt with. I'd like to improve the responsiveness of the app using this approach if possible.
Any ideas?

High CPU Load Average Debian

I am getting some warning from my Debian 8 server through nagios about average cpu load where top shows load average:
4.01, 3.66, 3.37
.... Sometimes increased to 5 where it shows critical. i am using php5-fpm and nginx with magento in this server. It has 20 cores and 12 GB ram.
top - 10:46:12 up 46 min, 1 user, load average: 3.47, 3.57, 3.38
Tasks: 257 total, 8 running, 249 sleeping, 0 stopped, 0 zombie
%Cpu(s): 23.5 us, 0.6 sy, 0.0 ni, 75.9 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem: 12327560 total, 9178948 used, 3148612 free, 451868 buffers
KiB Swap: 5241852 total, 0 used, 5241852 free. 4740264 cached Mem
Could anybody help me about this issue?
What is the normal CPU load average for this machine?

PHP-FPM consume all the CPU even there's no request

I got a very weird problem. My wordpress previously was working fine but recently and suddenly it turned very slow and the nginx returns 502 bad gateway sometimes. So I did some investigation, then I noticed the PHP-FPM processes consume all the CPU even there's no request. Everytime I restarted the wordpress the idle CPU usage just jumped to 0% instantly, and I can see several PHP-FPM processes were working with high CPU consumption, and the MySQL process consumed a lot CPU resource too, no matter if there is a request.
I tried to stop all the plugins - didn't work, same symptom.
I tried to update the wordpress to the latest version but DIDN't
connect to database - CPU usage is normal.
I tried to update the wordpress to the latest version and only keep the file wp-config.php (database username + pwd) - didn't work, same symptom.
This is so weird but seems it's related to the mysql database? But why?
Thanks in advance.
top - 02:08:12 up 56 min, 1 user, load average: 10.18, 9.41, 8.68
Tasks: 115 total, 11 running, 104 sleeping, 0 stopped, 0 zombie
Cpu(s): 36.6%us, 10.4%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.1%si, 53.0%st
Mem: 766112k total, 682116k used, 83996k free, 239696k buffers
Swap: 1572860k total, 2664k used, 1570196k free, 125412k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23854 www 20 0 59952 30m 4688 R 44.5 4.1 3:56.99 php-fpm
24337 www 20 0 60204 32m 4520 R 44.2 4.3 3:53.83 php-fpm
24300 www 20 0 52004 23m 4448 R 42.9 3.2 3:48.47 php-fpm
24287 www 20 0 54324 27m 5140 R 37.6 3.7 3:54.34 php-fpm
23855 www 20 0 54824 26m 4504 R 35.6 3.5 3:57.25 php-fpm
24323 www 20 0 46108 19m 4856 R 35.6 2.6 3:57.73 php-fpm
24274 www 20 0 56356 28m 4548 R 35.2 3.9 3:56.55 php-fpm
24374 www 20 0 55080 26m 4524 R 33.9 3.5 3:52.03 php-fpm
24385 www 20 0 63820 33m 4428 R 33.2 4.5 3:51.53 php-fpm
24394 www 20 0 57900 29m 4444 R 30.6 3.9 3:50.09 php-fpm
24250 mysql 20 0 214m 29m 5860 S 23.9 3.9 1:35.21 mysqld
6 root RT 0 0 0 0 S 1.7 0.0 0:01.31 watchdog/0
216 root 20 0 0 0 0 S 1.0 0.0 0:02.96 kjournald
23850 www 20 0 18624 11m 868 S 0.3 1.6 0:01.89 nginx
23851 www 20 0 18812 12m 876 S 0.3 1.6 0:03.61 nginx
27889 root 20 0 2712 1136 880 R 0.3 0.1 0:00.81 top
It turned out it's caused by an XML RPC attack. It's resolved now.
For more information:
https://medium.com/#tturnbull/throttle-xmlrpc-php-attacks-on-wordpress-with-nginx-3cc4a12b7f76

php-cgi not always terminating and locking sqlite

So I am having this occasional issue that is detrimental to my system. This is small embedded ARM system that is serving web pages using busybox's httpd. The pages are written in PHP and there is a sqlite3 backend.
What happens is occasionally when accessing pages on the system the system will start hanging. What i have found is that the culprit seems to be that sometimes php-cgi is not terminating. Something happens and it gets stuck open and it causes the sqlite3 database it accessed to be locked causing every other process to fail out trying to access it and basically everything slows to a crawl trying and failing to access this database. If you continue to browse pages they just build up and pretty soon you have something like this:
CPU: 34.2% usr 24.5% sys 41.0% nic 0.0% idle 0.0% io 0.0% irq 0.1% sirq
Load average: 10.99 3.36 1.31 23/131 2172
PID PPID USER STAT VSZ %VSZ CPU %CPU COMMAND
1229 1208 root S 107m 21.3 0 39.8 Router -t /tmp/volatileTables.d
1224 1208 root S 81852 15.9 0 14.4 Messenger -t /tmp/volatileTable
2103 2102 root R N 16740 3.2 0 2.1 /usr/bin/php-cgi all_stream.php
2106 2105 root R N 16264 3.1 0 2.1 /usr/bin/php-cgi all_stream.php
2109 2108 root R N 15612 3.0 0 2.1 /usr/bin/php-cgi all_stream.php
2112 2111 root R N 15092 2.9 0 2.1 /usr/bin/php-cgi all_stream.php
2115 2114 root R N 14708 2.8 0 2.1 /usr/bin/php-cgi all_stream.php
2118 2117 root R N 14296 2.7 0 2.1 /usr/bin/php-cgi all_stream.php
2121 2120 root R N 14036 2.7 0 2.1 /usr/bin/php-cgi all_stream.php
2124 2123 root R N 13908 2.7 0 2.1 /usr/bin/php-cgi all_stream.php
2127 2126 root R N 13908 2.7 0 2.1 /usr/bin/php-cgi all_stream.php
2131 2130 root R N 13908 2.7 0 2.1 /usr/bin/php-cgi all_stream.php
2135 2134 root R N 13776 2.6 0 2.1 /usr/bin/php-cgi all_stream.php
2142 2141 root R N 13776 2.6 0 2.1 /usr/bin/php-cgi all_stream.php
2145 2144 root R N 13776 2.6 0 2.1 /usr/bin/php-cgi all_stream.php
2151 2150 root R N 13776 2.6 0 2.1 /usr/bin/php-cgi all_stream.php
2160 2159 root R N 13332 2.5 0 2.1 /usr/bin/php-cgi all_stream.php
2163 2162 root R N 12936 2.5 0 2.1 /usr/bin/php-cgi all_stream.php
2166 2165 root R N 12780 2.4 0 2.1 /usr/bin/php-cgi all_stream.php
2154 2153 root R N 13776 2.6 0 1.9 /usr/bin/php-cgi all_stream.php
~ #
We were once able to get the load average all the way up to 50! Messenger and Router are applications trying to access the database being locked by all the php scripts.
Any clues for me as to how to proceed? Should I be using some other method to run the php files? Should I maybe try lighttpd instead of busybox's httpd? Is there something in my php.ini script I need to change maybe? Something bad i am doing in my php scripts themselves?
Any clue in the right direction would be helpful!

PHP 5.4 & Laravel Class 'Memcached' not found

I realize there are about 10 of these questions out there but none fit me completely.
Steps completed:
Installed memcache
installed php memcache module
updated laravel config to use memcache
Restarted server
php info results:
memcache.allow_failover 1 1
memcache.chunk_size 8192 8192
memcache.default_port 11211 11211
memcache.default_timeout_ms 1000 1000
memcache.hash_function crc32 crc32
memcache.hash_strategy standard standard
memcache.max_failover_attempts 20 20
memcached-tool results:
accepting_conns 1
auth_cmds 0
auth_errors 0
bytes 0
bytes_read 14
bytes_written 1096
cas_badval 0
cas_hits 0
cas_misses 0
cmd_flush 0
cmd_get 0
cmd_set 0
cmd_touch 0
conn_yields 0
connection_structures 6
crawler_reclaimed 0
curr_connections 5
curr_items 0
decr_hits 0
decr_misses 0
delete_hits 0
delete_misses 0
evicted_unfetched 0
evictions 0
expired_unfetched 0
get_hits 0
get_misses 0
hash_bytes 524288
hash_is_expanding 0
hash_power_level 16
incr_hits 0
incr_misses 0
libevent 2.0.21-stable
limit_maxbytes 268435456
listen_disabled_num 0
lrutail_reflocked 0
malloc_fails 0
pid 12022
pointer_size 64
reclaimed 0
reserved_fds 20
rusage_system 0.043400
rusage_user 0.065101
threads 4
time 1421438137
total_connections 7
total_items 0
touch_hits 0
touch_misses 0
uptime 2607
version 1.4.21
It is in php -m as "memcache"
However, when i go into php artisan tinker and try to do any caching I get the typical Fatal error: Class 'Memcached' not found in vendor/laravel/framework/src/Illuminate/Cache/MemcachedConnector.php on line 44
TL;DR;
I have confirmed install of memcache through multiple methods. Confirmed the module for php is installed. Still not allowing me to use memcached class.
If you are in a ubuntu environment, try to install Memcached with this:
sudo apt-get install php5-memcached
After that restart your server with
sudo service lighttpd restart
or
sudo service apachectl2 restart
or
sudo service nginx restart
Memcache and Memcached are two different PHP extensions. Memcache is the older deprecated one. Memcached is a much newer and fully supported extension.
Check out http://pecl.php.net/package/memcached
You may need to also install libmemcached https://launchpad.net/libmemcached/+download
apt-get install php-memcached
Solved the issue for "Class MemCached not found" coming from Laravel.
In Laravel/Lumen 5.4 just replace the CACHE_DRIVER=file in .env file, the artisan command will work perfectly, But you will not get all the command as same as laravel.

Categories