Home >Backend Development >PHP Problem >How many processes does php usually open?

How many processes does php usually open?

王林
王林Original
2019-09-28 11:55:275211browse

How many processes does php usually open?

First of all, let’s focus on how PHP-FPM runs:

static :表示在 `php-fpm` 运行时直接 `fork` 出 `pm.max_chindren` 个子进程,
 
dynamic:表示,运行时 `fork` 出 `start_servers` 个进程,随着负载的情况,动态的调整,最多不超过 `max_children` 个进程。

It is generally recommended to use static.

The advantage is that there is no need to dynamically determine the load situation and improve performance;

The disadvantage is that it takes up more system memory resources.

The number of PHP-FPM child processes, is the more the better?

Of course not, pm.max_chindren, there are too many processes, which increases the cost of process management and context switching. More importantly, the number of php-fpm processes that can be executed concurrently will not exceed the number of CPUs.

How to set it depends on your code

If the code is CPU-intensive, pm.max_chindren cannot exceed the number of cores of the CPU. If not, then it is very wise to set the value of pm.max_chindren to be greater than the number of cores of the CPU.

Formula:

Between N 20% and M / m.

Parameter description:

N is the number of CPU cores.

M is the amount of memory that PHP can utilize.

m is the average amount of memory used by each PHP process.

Suitable for dynamic mode.

static method: M / (m * 1.2)

Of course, there is also a safe way to configure max_children. Applies to static mode.

1. First set max_childnren to a relatively large value.

2. After running stably for a period of time, observe the max active processes in the status of php-fpm.

3. Then configure max_children to be larger than it is.

pm.max_requests: Refers to the number of requests each child process will restart after processing. This parameter can theoretically be set at will, but in order to prevent the risk of memory leaks, it is better to set a reasonable number.

Recommended video tutorial: PHP video tutorial

The above is the detailed content of How many processes does php usually open?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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