PHP Reload operations

Source: Internet
Author: User
Many predecessors warned us that reload can ensure the smoothness of the entire process. The so-called smoothness means that the old process will not be terminated before processing the current request. For many years, I have never questioned such a statement until one day, when I reload, there was a 502 error, so I had to rethink it. How can we reproduce the problem? Let's write a simple script Preface

Many predecessors warned us that reload can ensure the smoothness of the entire process. The so-called smoothness means that the old process will not be terminated before processing the current request. For many years, I have never questioned such a statement until one day, when I reload, there was a 502 error, so I had to rethink it.

How can we reproduce the problem? Let's write a simple script for simulation:

 



In this case, use your browser to browse the URL and immediately execute the reload operation. the error 502 is displayed.

Is PHP so weak? Even the basic smoothness of reload cannot be guaranteed? The answer is No.

process_control_timeout

Parameters can achieve our goal. Unfortunately, this parameter defaults to 0, that is, it does not take effect. This article sets it to 10 s. Re-execute the previous experiment step and output the result normally this time. However, if you do more experiments, you may find that when we reload, sleep is over immediately, because sleep returns directly after receiving the reload signal, next let's rewrite the script:

 



When you re-execute the previous experiment step, you will find that the error 502 has appeared again. This is because although reload immediately stops the first sleep, the second sleep is still valid and exceeds

process_control_timeout

. If we set

process_control_timeout

Set it to 12 s.

In this case, we only need

process_control_timeout

Setting a reasonable value can ensure the smoothness of the reload operation. but what is a reasonable value? If it is too small, it may not work. if it is too large, will it have any side effects? Let's repeat the previous experiment with questions, but this time we add another metric:

shell> watch -n1 'ps aux | grep php[-]fpm'



The purpose of this monitoring is to observe the changes in the number of PHP-FPM processes in the reload process, in order to make the effect more obvious, it is recommended to change the PHP-FPM startup mode to static mode, while the number of processes should not be too large.

When we repeat the previous experiment, we found that in addition to the process executing the request, other processes were killed directly, and the new process was not started immediately, in this way, the new process is started only after the last old process is executed. During this period, if other requests come in, it will undoubtedly not be able to get a response immediately.

According to our experiment, we can draw a conclusion: by default, the PHP-FPM cannot ensure smooth reload operation, must set a reasonable

process_control_timeout

At the same time, you must note that the value cannot be set too large, otherwise the system may encounter more serious request congestion problems.

Summary

The above is all about the Reload operations in PHP. For more information, see PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.