Table of Contents
Similarities of PHP-FPM Process Manager (PM) and CPUFreq Regulator
Use pm staticAchieve maximum performance of the server
Conclusion
How does PHP-FPM improve my website performance?
What is the pm static configuration in PHP-FPM and how does it affect performance?
How to monitor the performance of PHP-FPM?
What are some best practices for using PHP-FPM?
Home Backend Development PHP Tutorial PHP-FPM tuning: Using 'pm static' for Max Performance

PHP-FPM tuning: Using 'pm static' for Max Performance

Feb 09, 2025 am 08:25 AM

PHP-FPM tuning: Using 'pm static' for Max Performance

Key Points

  • For adequate memory servers, the pm static setting of PHP-FPM provides high throughput and low latency. This setting allows PHP-FPM processes to maintain maximum capacity at all times, enabling rapid response to traffic peaks without the need to generate new processes.
  • Using pm static Careful adjustment is required to avoid insufficient memory or cache stress issues. pm.max_children It should be set according to the maximum number of PHP-FPM processes the server can handle without affecting CPU performance.
  • For servers with multiple PHP-FPM pools or low memory, pm dynamic or pm ondemand may be more suitable. These settings can save memory by adjusting the number of subprocesses based on the current load, but can also cause overhead issues when traffic fluctuations are occurring.
  • Regular monitoring and tuning of PHP-FPM configuration is essential for optimal performance regardless of the settings you choose. The average size of PHP-FPM processes varies from server to server and requires manual adjustment and a clear understanding of the server's resource and traffic patterns.

The original manuscript of the article was originally published on HaydenJames.io without editing and was reproduced here with permission from the author.

Let us quickly learn how to best set up PHP-FPM for high throughput, low latency, and more stable CPU and memory usage. By default, most settings set the PM (process manager) string of PHP-FPM to dynamic, and ondemand is usually recommended if you encounter available memory problems. However, let's compare these two management options based on the documentation of php.net and compare my favorite options for high traffic settings - static pm:

  • pm = dynamic: The number of child processes is dynamically set according to the following instructions: pm.max_children, pm.start_servers, pm.min_spare_servers, pm.max_spare_servers.
  • pm = ondemand: The process is generated on request as needed, which is different from dynamic, which starts at the service starts pm.start_servers.
  • pm = static: The number of child processes is fixed by pm.max_children.

See the complete list of global php-fpm.conf directives for more details.

Similarities of PHP-FPM Process Manager (PM) and CPUFreq Regulator

This may seem a bit off topic, but I would like to associate it with our PHP-FPM tweaked topic. OK, we all have had slow CPU speeds at some point, whether it’s a laptop, a virtual machine, or a dedicated server. Remember CPU frequency scaling? (CPUFreq regulator.) These settings are available on both nix and Windows systems, and can improve performance and system responsiveness by changing the CPU regulator settings from ondemand to performance*. This time, let's compare the description and look for similarities:

  • Governor = ondemand: Dynamically scale the CPU frequency according to the current load. Jump to the highest frequency and then decrease the frequency as the idle time increases.
  • Governor = conservative: Dynamically scale the frequency according to the current load. Scaling frequency smoother than ondemand.
  • Governor = performance: Always run the CPU at maximum frequency.

See the complete list of CPUFreq regulator options for more details.

Did you notice the similarity? I want to use this comparison first, with the goal of finding the best way to write an article, recommending pm static of PHP-FPM as your first choice.

For CPU regulators, the performance setting is a fairly safe performance boost, as it almost entirely depends on the limitations of your server CPU. Other factors are just side effects such as heat, battery life (laptop), and permanently setting the CPU frequency to 100%. Once set to performance, it is indeed the fastest setup for the CPU. For example, read about the force_turbo setting on the Raspberry Pi, which forces your RPi board to use a performance regulator, and performance improvements are more noticeable due to the low CPU clock speed.

Use pm staticAchieve maximum performance of the server

PHP-FPM pm static Settings depend heavily on how much memory the server has. Basically, if you're having problems with insufficient server memory, then pm ondemand or dynamic may be a better choice. On the other hand, if you have enough memory available, you can avoid most of the PHP Process Manager (PM) overhead by setting pm static to the maximum capacity of the server. In other words, when you do calculations, pm.static should be set to the maximum number of PHP-FPM processes that can run without creating memory availability or cache stress issues. Also, don't set it too high to overwhelm the CPU(s) and cause a lot of unprocessed PHP-FPM operations.

PHP-FPM tuning: Using 'pm static' for Max Performance

In the above image, the pm = static and pm.max_children = 100 of this server use up to about 10GB of 32GB of installed memory. Please note the highlighted columns of self-interpretation. During this screenshot, there were about 200 "active users" in Google Analytics (last 60 seconds). At this level, approximately 70% of PHP-FPM child processes are still idle. This means that PHP-FPM is always set to the maximum capacity of the server resource regardless of the current traffic. The idle process stays online, waiting for traffic peaks and responding immediately, instead of having to wait for pm to spawn child processes and then close it after pm.process_idle_timeout expires. I've set pm.max_requests very high because this is a production server without PHP memory leaks. If you have 110% confidence in current and future PHP scripts, you can use pm.max_requests = 0 in static. However, it is recommended to restart the script regularly. Set the number of requests to a higher number, because the point is to avoid pm overhead. For example, at least pm.max_requests = 1000, depending on your pm.max_children number and requests per second.

This screenshot is filtered using Linux top, by the “u” (user) option and the name of the PHP-FPM user. The number of processes displayed is only about 50 (no calculations), but basically top displays top-level statistics that suit your terminal window—in this case, sorted by %CPU. To view all 100 PHP-FPM processes, you can use the following command:

<code>top -bn1 | grep php-fpm</code>
Copy after login

When to use pm ondemand and dynamic

Using pm dynamic, you may have noticed errors similar to the following:

<code>WARNING: [pool xxxx] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 4 idle, and 59 total children</code>
Copy after login

You may try to increase/adjust settings, but you will still see the same error as someone described in the Serverfault post. In this case, pm.min is too low and it is difficult to adjust correctly because network traffic fluctuates greatly with troughs and peaks. The usual advice is to use pm dynamic. However, this is even worse because when there is little or no traffic, pm ondemand will shut down the idle process to 0, and then you will end up with as much overhead problem as the traffic fluctuates – unless, of course, you will be idle Timeout is set to extremely high... In this case you should only use ondemand highpm.static. pm.max_requests

However, when you have multiple PHP-FPM pools, PM dynamic, especially ondemand, can save you resources. For example, host multiple cPanel accounts or multiple websites under different pools. For example, I have a server that has over 100 cPanel accounts and about 200 domain names, pm.static and even dynamic do not do well. Only ondemand can execute well, as more than two-thirds of the websites have little traffic. Using ondemand, this means that all child processes will be shut down, saving a lot of server memory! Thankfully, cPanel developers have solved this problem and now it defaults to ondemand. Previously, due to the use of dynamic by default, it made PHP-FPM an option on a shared server even on an idle cPanel PHP-FPM pool/account. If you receive good traffic, you are unlikely to host on a server with a large number of PHP-FPM pools (shared hosts).

Conclusion

In PHP-FPM, once you start providing a large amount of traffic, the ondemand and dynamic process managers of PHP-FPM may limit throughput due to inherent overhead. Understand your system and set your PHP-FPM process to match the maximum capacity of the server. Start with the maximum usage setting based on pm dynamic or ondemand and increase to the point where the memory and CPU can handle without being overwhelmed. You will notice that using pm.max_children is because you let everything reside in memory, over time, the traffic peak will cause the CPU to peak and the server’s load and CPU average will be smoother. The average size of your PHP-FPM process varies by web server and needs to be adjusted manually, so why the more automated overhead process managers—pm static and dynamic—a more popular suggestion. Hope this article helps you. ondemand

Update: Added A/B benchmark comparison chart. Having PHP-FPM processes reside in memory helps improve performance, but at the cost of increasing memory usage to keep them in a wait state. Find the best point for your settings.

PHP-FPM tuning: Using 'pm static' for Max Performance

FAQs about PHP-FPM Adjustments (FAQ)

What is PHP-FPM and why is it important to my server performance?

PHP-FPM or FastCGI Process Manager is another PHP FastCGI implementation that has some additional features useful for sites of any size, especially for busy sites. It is important for server performance because it allows the server to handle more requests from simultaneous visitors by leveraging the worker pool. These processes are responsible for parsing PHP files, generating dynamic content and providing them to clients. By effectively managing these processes, PHP-FPM can significantly improve server performance and scalability.

How does PHP-FPM improve my website performance?

PHP-FPM improves website performance by effectively managing PHP processes. It uses the main process to control multiple child processes that process PHP scripts. This allows efficient use of server resources, as idle processes can be terminated and new processes can be generated as needed. Additionally, PHP-FPM supports opcode caching, which can significantly speed up PHP execution by storing precompiled script bytecode in shared memory, eliminating the need for PHP to load and parse scripts on every request.

What is the pm static configuration in PHP-FPM and how does it affect performance?

pm static in PHP-FPM The

configuration sets the number of child processes to a fixed number. This means that there will always be a specific number of processes ready to serve incoming requests regardless of the current server load. This can lead to better performance under high loads, as new processes are not required to be generated. However, it can also lead to higher memory usage, because they are always running even if these processes are not needed.

How to adjust PHP-FPM for maximum performance?

pm Adjusting PHP-FPM for maximum performance involves tuning multiple configuration settings. These settings include the pm.max_children settings that determine the process manager to use, and the pm.start_servers settings that set the maximum number of child processes. Other important settings include pm.min_spare_servers, pm.max_spare_servers and

, which control the number of servers started, the minimum number of idle servers, and the maximum number of servers respectively. Adjusting these settings to match the server's resource and traffic patterns can significantly improve performance.

What are some common problems with PHP-FPM and how can I troubleshoot it?

pm.max_childrenSome common problems with PHP-FPM include high CPU usage, slow response time, and errors related to reaching the maximum number of child processes. These problems can often be solved by adjusting the PHP-FPM configuration settings, such as adding

settings or switching to a different process manager. Additionally, monitoring tools can be used to identify bottlenecks and performance issues.

How does PHP-FPM compare to other PHP handlers?

PHP-FPM is generally considered to be more efficient and flexible than other PHP handlers. It supports various process managers and can be adjusted according to the server's resources and traffic patterns. Additionally, PHP-FPM supports opcode caching and can handle a large number of simultaneous requests, making it ideal for busy sites.

Can I use PHP-FPM with any web server?

Yes, PHP-FPM can be used with any web server that supports the FastCGI protocol. This includes popular web servers such as Apache, Nginx, and Lighttpd.

What is opcode caching and how does it improve PHP performance?

Opcode caching is a technology that improves PHP performance by storing precompiled script bytecode in shared memory. This eliminates the need for PHP to load and parse scripts on every request, reducing execution time.

How to monitor the performance of PHP-FPM?

Several tools are available for monitoring the performance of PHP-FPM. These tools include the PHP-FPM status page (which provides information about the current state of the worker process) and various command-line tools such as top and ps. In addition, there are some third-party monitoring solutions that provide more detailed metrics and alerts.

What are some best practices for using PHP-FPM?

Some best practices with PHP-FPM include: adjusting process manager settings to match the server's resource and traffic mode; enabling opcode caching; and regularly monitoring performance to identify and resolve issues. Additionally, be sure to keep PHP-FPM and web server software up to date to take advantage of the latest performance improvements and security fixes.

The above is the detailed content of PHP-FPM tuning: Using 'pm static' for Max Performance. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles