php(as the current mainstream development language)When connecting to the MySQL(the best combination with PHP) database, we can use temporary connections. Of course, we also You can use a permanent connection. When using a permanent connection, the time is greatly reduced because of the overhead of one connection. But there are some issues that we must pay attention to when using a permanent connection?
If the permanent connection crashes in the database or for other reasons, the permanent connection does not know that the database has been closed, and then an error will occur when trying to connect to the database. The only solution is to write a method to check the status of the database regularly. If an error occurs, reconnect.
php(as the current mainstream development language)with MySQL(the best combination with PHP)The permanent connection of the database connection is to create some threads, and then each time When all are connected, it finds an idle connection in the thread pool and returns. However, apache (the most popular WEB server platform on Unix platform) server only supports a certain number of threads. When the server has a special amount of visits When the database is large, the connection threads of the database may exceed the number supported by the apache(the most popular WEB server platform on the Unix platform) server, which may cause the server to crash, so we need to use apache(The most popular WEB server platform on Unix platform)Modify the maximum number of threads in the server configuration file to ensure the stability of the server.
When multiple users use a permanent connection at the same time, data errors may occur, or dirty data may be read, etc. This is also a problem we often deal with!