12.21 PHP-FPM's Pool
PHP-FPM has a concept called pool, that is, the right side of the Psaux to see the column, that is, its pool,
For example, here we define only a pool
In fact, he is supporting the definition of multiple pools, each pool we can listen to different sock, or different tcpip, so if our nginx has several sites each site can use a different pool, the advantage is one of the php502, other sites do not affect, (502 probably not enough PHP resources) if all of your sites are using the same pool, one of the sites has failed, such as the programmer wrote the code has a problem of the PHP resources exhausted, then the other several will be 502, so we need to isolate the site, Each site uses a separate pool.
To add multiple pool methods:
You can continue adding in the file as in, such as adding a pool called aming.com to add the following paragraph after the contents of the file.
Then we check for errors,
and then reload.
Then we look at the pool and we can see a aming.com pool on the right.
So how do we use it?
First, then, define the test.com.conf as Php-fcgi.sock.
Then define the other aaa.com.conf as Aming.sock, (if it doesn't have this section then copy it from the test.com.conf)
So two sites are separated from each other.
Of course PHP-FPM also supports include,
Then, after entering into this directory, and then the php-fpm.conf in the WWW cut into the www.conf, and then the php-fpm.conf in the Aming.com section cut into the inside.
Then we check for errors,
and then reload. The effect is the same as the first.
12.22 php-fpm Slow Execution log
We first
It means logging in more than a second (if we recommend two seconds in real-world scenarios, many scripts will take more than a second), and then put them in the address of the second line.
Then check the error reload, and then we can see if there are any log files generated in this directory. We can see if there is anything inside. The inside should be empty, because we don't have any more than a second of PHP execution, so we need to emulate a slow-executing PHP.
Then we'll write a script, because php-fcgi is used by test.com, so we need to do it under this site.
We do a script deliberately let it sleep for 2 seconds
We can divide it into three lines.
Then we'll run it and try it (if there's no output that means there's an error)
There's a line in it. After we open it, we change it to on, and we can display the error in the browser or curl. And then we run again, such as prompt US syntax error
Here should be our sleep.php punctuation is written in Chinese punctuation, we can change it to English, and then we run again, it is possible to see that the execution of the process is a pause for two seconds.
And we're looking at the logs.
Now there will be content, such as
The second line tells us that the sleep.php script is slow, and the third line says the 3rd line of the script is slow.
We can take a look at what the third line of the script is, such as exactly what we set to hibernate for 2 seconds.
12.23 Open_basedir
Open_basedir we also introduced before, if the server has multiple sites, then the definition in the php.ini is not appropriate, so either in the Apache virtual host configuration file defined, or defined in PHP-FPM, then we can define for each pool Open_ Basedir
Define the method as long as the WWW (also can be other pool) pool file Add, and then another line (here the site must write www This file corresponds to the site, not the standard answer), such as adding it. It then reloads after checking for errors, and then it can be accessed.
We can also take a look at its error log, we first change the switch to OFF, (normal is closed, because you can not let others through the browser to see the error message) and then we define the error log path, (the original comment, and then another line)
Also define the log level (here we define all, we put the original comment, and then another line)
Then create the specified error log path file
Then we deliberately changed the later site defined in www.conf to another site.
Then check the error reload and then access it to generate the error log, then we can look at the error log
12.24 PHP-FPM Process Management
PHP-FPM process Management is the PHP-FPM configuration file, such as a few lines selected in www.conf.
The first line shows you the process in what form to start, dynamic is dynamically, only dynamic when all the following parameters are in effect, if you change to static then only the following to take effect, that is, the start of the time to generate 50.
Dynamic dynamics, the following line at the end of 20 means that the default startup of 20, the request will increase the number of times, but the idle time more than 35 will be automatically reduced, the end of the line below 5 means the lowest of not less than 5, 500 of the line means that each child process processing the number of requests is 500 times, When this value is reached, it exits automatically.
Of course, the numbers behind these parameters can be changed.
We can change it and reload php-fpm, then we can look at the number of processes on the site:
12.21 php-fpm pool 12.22 php-fpm Slow execution log 12.23 open_basedir 12.24 PHP-FPM Process Management