For example, when each page ends, the database connection is closed. On the next page, you need to re-open the database and re-connect to obtain data. In this way, what are the major disadvantages and minor advantages of websites with persistent connection. For example, when each page ends, the database connection is closed. On the next page, you need to re-open the database and re-connect to obtain data. In this way, what are the major disadvantages and minor advantages of websites with persistent connection.
Reply content:
For example, when each page ends, the database connection is closed. On the next page, you need to re-open the database and re-connect to obtain data. In this way, what are the major disadvantages and minor advantages of websites with persistent connection.
First, the default database is mysql.
Then, most web application scenarios are suitable for short links instead of long links. For example, when you read a novel, after obtaining the current chapter of the novel, the user will not start a new link for a long time. Why not release the link to the desired user? The disadvantage is that repeated release links are also a loss.
As for long links, simply put, it is the opposite of the above.
In fact, it will be much better if you have an SQL connection pool.
I am an easy-to-learn hacker.
The advantage is that it is simple .....
Every time a database is connected, it involves many Unix System calls. The total consumption of database connection is huge.
For virtual host providers, short connections are friendly.
For example, the VM vendor enables 100 Apache or PHP-FPM workers to drive 50 VM sites,
If one site corresponds to one persistent connection to MySQL, one worker process may maintain 50 persistent connections,
100 worker processes are 100*50 = 5000 persistent connections,
The maximum number of connections of MySQL max_connections is 151 by default,
These 5000 connections are still under great pressure on the MySQL server.
For servers with only one application, after persistent connection is enabled,
A PHP-FPM keeps a persistent connection to MySQL for transparent "connection pool ",
This reduces the overhead of repeatedly establishing and releasing connections for each request to improve performance.
PHP FastCGI Process Manager PHP-FPM Architecture
Http://my.oschina.net/eechen/blog/541139