Ever wondered how well your server handles high traffic?
Currently I'm studying how to optimize PHP-FPM performance, especially for applications like Laravel and WordPress. One of the most crucial settings is pm.max_children, which determines how many child processes PHP-FPM can spawn to handle incoming requests.
So, instead of running a multiple pm.max_children values and guessing which one is best, I decided to benchmark it using wrk, a modern HTTP benchmarking tool. This way, I can find the optimal value for pm.max_children based on real data and results in one go.
This guide helps you benchmark your PHP-FPM performance using wrk. A modern HTTP benchmarking tool to find the optimal value for pm.max_children. This is especially useful if you're running Laravel, WordPress, or any PHP-based application on a VPS.
Sometimes your server feels "fine", until traffic spikes. And then things start to choke. One of the key reasons? PHP-FPM runs out of available child processes.
So instead of guessing, we'll test. You'll install wrk, write a simple bash script to automate the benchmarks, and analyze which pm.max_children value gives the best throughput and lowest latency.
Real data. Real results. No guesswork.
Hi, I'm Sulaiman Misri. Currently I'm working as a Senior Full Stack Engineer at one of the Big Four Companies in Malaysia (Property). If you find this snippet is useful, feel free to check out my portfolio for more information about me and my freelance services.
Install wrk inside your Ubuntu/Debian by running :
sudo apt install build-essential libssl-dev git -y
git clone https://github.com/wg/wrk.git
cd wrk
make
sudo cp wrk /usr/local/bin
This approach is the best approach to make sure you have the latest version of wrk installed.
Test the installation by running:
wrk --version
You will see the output like this and you are good to go:
wrk 4.2.0 [epoll] Copyright (C) 2012 Will Glozer
You need to create a bash script. You can named it with any name you want, for example benchmark.sh. Create it by running :
nano benchmark.sh
If there's error, you can use sudo nano benchmark.sh to create the file.
Copy and paste the following code into the benchmark.sh file:
#!/bin/bash
CONF_PATH="/etc/php/your_php_version/fpm/pool.d/your_pool_name.conf"
URL="your_application_url"
OUT_DIR="$HOME/wrk-results"
DURATION="how_many_seconds_to_run"
THREADS=4
CONNECTIONS=100
mkdir -p "$OUT_DIR"
for MAX_CHILDREN in 60 80 100 120 140; do
echo "====================================="
echo "Testing with pm.max_children = $MAX_CHILDREN"
echo "====================================="
# Update pm.max_children
sudo sed -i "s/^pm.max_children = .*/pm.max_children = $MAX_CHILDREN/" "$CONF_PATH"
# Restart PHP-FPM & Nginx (change the php8.3-fpm to your PHP version)
sudo systemctl restart php8.3-fpm
sudo systemctl restart nginx
sleep 3 # short delay to make sure everything is back
# Run wrk
OUTPUT_FILE="$OUT_DIR/result_${MAX_CHILDREN}.txt"
wrk -t$THREADS -c$CONNECTIONS -d$DURATION "$URL" | tee "$OUTPUT_FILE"
done
You need to give this file an executable permission by running:
chmod +x benchmark.sh
Go to the root directory of your Server and run the script by executing:
./benchmark.sh
You will later see the result in your terminal like this :