Linux PHP tuning utilities & commands
1. See memory consumed by php-fpm8.2 (change this to match different PHP version if necessary)
ps --no-headers -o "rss,cmd" -C php-fpm8.2 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
1. See memory consumed by php-fpm8.2 (change this to match different PHP version if necessary)
ps --no-headers -o "rss,cmd" -C php-fpm8.2 | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
Run from Github:
curl -L https://raw.githubusercontent.com/BMDan/tuning-primer.sh/main/tuning-primer.sh | bash
wget http://mysqltuner.pl/ -O mysqltuner.pl
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/basic_passwords.txt -O basic_passwords.txt
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/vulnerabilities.csv -O vulnerabilities.csv
perl mysqltuner.pl --host 127.0.0.1 --user [user] --pass [pass]
Remember to quote any punctuation or BASH tokens in the password.
This was a system service that ren every time the CPU spiked and logged what was running. Mostly it showed that php-fpm was what spiked the CPU. Fascinating.
daemon was at /etc/systemd/system/mk-cpu-watcher.service
[Unit]
Description=CPU Usage Watcher
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/mk-cpu-watcher.sh
Restart=always
[Install]
WantedBy=multi-user.target
script it ran was at /usr/local/bin/mk-cpu-watcher.sh
#!/bin/bash
LOG_FILE="/var/log/mk-cpu-spikes.log"
THRESHOLD=98 # Can set to threshold just below 100 to catch near-maximum usage
while true; do
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2+$4}' | cut -d. -f1)
if [ "$CPU_USAGE" -ge "$THRESHOLD" ]; then
echo "=== CPU spike detected at $(date) - Usage: ${CPU_USAGE}% ===" >> "$LOG_FILE"
echo "Top processes:" >> "$LOG_FILE"
ps -eo pid,ppid,cmd,%cpu,%mem --sort=-%cpu | head -11 >> "$LOG_FILE"
echo -e "\n" >> "$LOG_FILE"
fi
sleep 5 #…
For confused first-time visitors and other people still acclimating, here is a description of these little tabs to the left, as well as some other features of the site.
Open "Expert Mode" CLI Navigation - this give you the option to switch your browser's display to an old-fashioned terminal mode where you may browse this site, view pages and images by typing text commands. Just like how we used to browse the web back in 1978!
Open Visual Settings - This gives you controls to customize the visual display of this website to your liking: turn up or down the brightness, contrast, color temperature, hue, saturation, dark mode, and earthquake. Settings are saved per browser tab, so they will be remembered for your whole visit.
Open My Eyes - Have you ever been engrossed in your work, when you suddenly realize someone is staring at your screen, watching everything you do over your shoulder? If not, this simulates the experience.
Open Help - This help popup, silly! You just clicked it! Do you not remember?
New - Draggable elements! Several elements on this website, including these tabs, this popup message, and the "Hire Mike" badge in the lower right, can be dragged around with your mouse, to avoid them blocking content. Positions are remembered per tab, so as you navigate around the site, they will stay in the same place for your whole visit.
Enjoy!
Are you sure you want to switch to viewing this website in the "expert mode" command-line interface?
This will switch to a terminal emulator, load this page, and allow you to browse this website and view its contents by typing text commands.
Plus there might be, y'know, some fun stuff hidden in there. Just for geeks.