Home  >  Article  >  PHP Framework  >  How to hot update swoole

How to hot update swoole

(*-*)浩
(*-*)浩Original
2019-12-07 13:59:313029browse

With the iterative update of swoole version, it has become stable enough. It is used by major companies such as Alibaba, Tencent, YY, etc., and is also used by many friends in the gaming circle. These friends often mention a question, Every time the code is updated, the service needs to be stopped and then restarted to update the code. However, this approach is relatively crude.

How to hot update swoole

In fact, swoole provides the reload feature and fully supports hot updates of code.

Before introducing swoole's reload, let's briefly talk about how the web method takes effect immediately after changing the file:

A few Concept: (Recommended Learning: Swoole Video Tutorial )

## 1) SAPI: It can be simply understood as a unified interface of the PHP engine, so that PHP can interact with external programs to interact

2) Four key calls in the life cycle of php: MINT -> RINT -> RSHUTDOWN -> MSHUTDOWN

3) fpm: fastcgi process manager


Then the process of fpm method is: fpm interacts with the php process through the sapi interface. When fpm starts,


The first step: The MINT method of each extension will be called to process some data Initialization (resident in memory),

The second step: For each request, RINT will be executed to initialize the single request first,

The third step: Execute the php script,

Step 4: Execute the RSHUTDOWN method,

Step 5: If you want to stop fpm, MSHUTDOWN will be executed.

fpm processes each request by repeatedly executing steps 2~4.

In the third step, the php script is executed dynamically, because the php script must be executed every time, and each php script must have a translation of the php file into The opcode process (which is relatively time-consuming) led to the creation of the opcache tool.


opcache: Directly save the PHP-translated opcode code tree to the shared memory for direct use, thereby reducing the overhead of translating PHP into opcode every time.


opcache problem: According to his description, the php file was modified and could not be updated immediately.


opcache solution: There is a configuration to set the interval Detect whether the file has been updated for a long time, so that you have the opportunity to reload the related files in the second step.


Of course, you can also directly reload fpm to achieve the effect of PHP hot update (opcache extension You can clear the relevant opcode cache in the fourth step).

The above is the detailed content of How to hot update swoole. 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
Previous article:How to turn on swooleNext article:How to turn on swoole