Operations 4 min read

Boost High‑Load PHP Performance: Essential Linux Tuning Tips

This guide presents practical Linux system tweaks and PHP configuration adjustments—including file descriptor limits, disabling atime, using tmpfs, and optimizing php.ini and PHP‑FPM settings—to dramatically improve high‑load PHP application responsiveness and stability.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost High‑Load PHP Performance: Essential Linux Tuning Tips

High‑Load PHP Tuning

Linux tuning for PHP

Adjust file descriptor limits

# ulimit -n 1000000
# vi /etc/security/limits.conf
# Setting Shell Limits for File Descriptors
*  soft nofile 1000000
*  hard nofile 1000000

Disable atime updates on the PHP code partition

# vi /etc/fstab

For example, the partition containing PHP code: /dev/sdb1 ext4 errors=remount-ro 0 1 Change to:

/dev/sdb1   ext4    noatime,nodiratime,errors=remount-ro  0  1

Store temporary files on tmpfs

When handling many small image uploads (e.g., user avatars), using a memory‑based tmpfs reduces I/O overhead, but it is unsuitable for very large files such as videos.

# vi /etc/fstab
tmpfs   /tmp   tmpfs   defaults,nosuid,noatime 0 0

PHP configuration tuning

php.ini tuning

# vi php-app.ini
[PHP]
engine = On
expose_php = Off

max_execution_time = 5
memory_limit = 256M
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = Off
display_startup_errors = Off
html_errors = Off
default_socket_timeout = 5

file_uploads = On
upload_tmp_dir = /tmp/php
upload_max_filesize = 50M
post_max_size = 50M
max_file_uploads = 20

date.timezone = 'Asia/Shanghai'

Note that max_execution_time is set to only 5 seconds. For a fast web application we aim for request latency of 300‑500 ms; any request exceeding 5 seconds usually indicates a problem.

PHP‑FPM tuning

# vi php-fpm.conf
[my_app]
;FastCGI/PHP‑FPM using UNIX sockets
listen = /data/my_app/tmp/php.sock
listen.backlog = 300
user = www
group = www
pm = dynamic
; Estimate pm.max_children = (MAX_MEMORY - 500MB) / 20MB
pm.max_children = 100
; Recommended as 10% of max_children
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
pm.max_requests = 1000
pm.status_path = /php_status

request_terminate_timeout = 0
request_slowlog_timeout = 0
slowlog = /data/my_app/logs/slow.log
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceOperationsTuning
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.