Docs / Performance Optimization / Optimizing PHP-FPM Worker Configuration

Optimizing PHP-FPM Worker Configuration

By Admin · Jan 18, 2026 · Updated Apr 23, 2026 · 6 views · 3 min read

In this article, we'll walk through the complete process of working with php-fpm in a server environment. Understanding workers is essential for maintaining a reliable and performant infrastructure.

Prerequisites

  • Access to system monitoring tools (htop, iostat)
  • Current baseline performance metrics for comparison
  • Root or sudo access to the server

Baseline Measurement

The workers component plays a crucial role in the overall architecture. Understanding how it interacts with php-fpm will help you make better configuration decisions.


# Kernel tuning: /etc/sysctl.d/99-performance.conf
cat << 'EOF' | sudo tee /etc/sysctl.d/99-performance.conf
# Network performance
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15

# Memory management
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5

# File descriptors
fs.file-max = 2097152
fs.nr_open = 2097152
EOF

sudo sysctl --system

Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.

Kernel and OS Tuning

When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.


# Benchmark before and after optimization
# CPU benchmark
sysbench cpu --cpu-max-prime=20000 run

# Memory benchmark
sysbench memory --memory-block-size=1M --memory-total-size=10G run

# Disk I/O benchmark
sysbench fileio --file-total-size=4G --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=4G --file-test-mode=rndrw run
sysbench fileio --file-total-size=4G cleanup

Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.

Application-Level Optimization

If you encounter issues during setup, check the system logs first. Most problems can be diagnosed by examining the output of journalctl or the application-specific log files in /var/log/.


# Kernel tuning: /etc/sysctl.d/99-performance.conf
cat << 'EOF' | sudo tee /etc/sysctl.d/99-performance.conf
# Network performance
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15

# Memory management
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5

# File descriptors
fs.file-max = 2097152
fs.nr_open = 2097152
EOF

sudo sysctl --system

Each line in the configuration serves a specific purpose. The comments explain the reasoning behind each setting, making it easier to customize for your specific use case.

Caching Strategy

It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.


# Benchmark before and after optimization
# CPU benchmark
sysbench cpu --cpu-max-prime=20000 run

# Memory benchmark
sysbench memory --memory-block-size=1M --memory-total-size=10G run

# Disk I/O benchmark
sysbench fileio --file-total-size=4G --file-test-mode=rndrw prepare
sysbench fileio --file-total-size=4G --file-test-mode=rndrw run
sysbench fileio --file-total-size=4G cleanup

This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.

Performance Considerations

Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.

Next Steps

With php-fpm now set up and running, consider implementing monitoring to track performance metrics over time. Regularly review your configuration as your workload changes and scale resources accordingly.

Was this article helpful?