|
The mysqli Extension and Persistent ConnectionsThe idea behind persistent connections is that a connection between a client process and a database can be reused by a client process, rather than being created and destroyed multiple times. This reduces the overhead of creating fresh connections every time one is required, as unused connections are cached and ready to be reused.
Unlike the mysql extension, mysqli does not provide a separate function
for opening persistent connections. To open a persistent connection you
must prepend
The problem with persistent connections is that they can be left in
unpredictable states by clients. For example, a table lock might be
activated before a client terminates unexpectedly. A new client
process reusing this persistent connection will get the connection
The persistent connection of the
This ensures that persistent connections are in a clean state on return from the connection pool, before the client process uses them.
The The automatic cleanup feature has advantages and disadvantages though. The advantage is that the programmer no longer needs to worry about adding cleanup code, as it is called automatically. However, the disadvantage is that the code could potentially be a little slower, as the code to perform the cleanup needs to run each time a connection is returned from the connection pool.
It is possible to switch off the automatic cleanup code, by compiling
PHP with
|