PHP in connection with the MySQL database when we can use a temporary connection, of course, we can also use permanent connection, the use of permanent connection because of the cost of a connection, so the time is greatly reduced, but we only use a permanent connection when we must pay attention to some of the problems?
Permanent connection in the case of a database crash or otherwise, a permanent connection does not know that the database has been shut down, and then to connect to the database will be wrong, the solution is to write a method to check the state of the database regularly, if the error on the new connection.
The permanent connection between PHP and the MySQL database is to create some threads, then find an idle connection in the thread pool every time you connect, but the Apache server only supports a certain number of threads, and when the server's traffic is particularly high, The connection threads of the database may exceed the number of Apache server support, which may cause the server to crash, so we need to modify the maximum number of threads in the configuration file of the Apache server to keep the server stable.
When multiple users use a permanent connection at the same time, may be back to the data error, or read dirty data, and other circumstances, this is our often to the issue of the doctrine!