About "lasting database connection"

xiaoxiao2021-03-06  98

About database connection assignment, multi-process model (such as

Apache

There is still a problem. This problem is speaking with me.

PHP

The failure characteristics of the script are relatives. Please take a look at the picture below.

This picture you have seen from a dynamic driven by database

Web

Application perspective

Apache / PHP

How does the solution work and process access requests. You may notice that as mentioned above, each

Apache

The child process processes a separate client connection once. due to

PHP

Scripts are separately accessed

PHP

Each sub-process for generating a request for a document is interpreted, each process must establish a connection of its independent query database.

due to

PHP

The script has no persistence, and the database connection must be turned on and off at each script. Especially for those sites that are frequently accessed, it may cause huge performance losses in connection.

In order to avoid this,

PHP

Developers may use a long-lasting database connection to make access requests are processed and

PHP

The script remains open after the end of the script.

But when

PHP

Industrial connection and traditional connections in the environment

"

Pool

"

The way is not the same. in

PHP

In the environment, when a persistent connection is opened by a child process, it is possible to reuse the connection without an additional connection time. However, it is to be pointed out that it can only be reused by the same child process. Since the connection is opened by a particular process, even if the sub-process is opened, this connection is not used to handle any request. In fact, even if the child process continues to deal with another

PHP

Request, the database connection will not be closed.

In the case of a lasting database connection, what we observed is actually the same sub-process as the previous

HTTP Keepalive

Requested

1

:

1

Mapping ratio. However, in the current case, the database connection will remain open and run through the entire life period of opening its child processes.

This situation can cause the open database to connect excess, so that the occupied memory space exceeds the actual load. In some environments, this database connection is excess to the limit of the number of connections in high loads. At this time, the server will no longer respond to more requests. Users can regard this situation as an application server or

HTTP

The server executed a denial of service attack on the database, thus making itself a machine.

转载请注明原文地址:https://www.9cbs.com/read-124355.html

New Post(0)