From a923f2372273f83b14b2b7410bb08a6aaaeb8283 Mon Sep 17 00:00:00 2001 From: Anthony Bedford Date: Tue, 24 Feb 2009 17:52:10 +0000 Subject: [PATCH] Initial information about mysqli persistent connection support. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@276358 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mysqli/persistconns.xml | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 reference/mysqli/persistconns.xml diff --git a/reference/mysqli/persistconns.xml b/reference/mysqli/persistconns.xml new file mode 100644 index 0000000000..5a11dafa68 --- /dev/null +++ b/reference/mysqli/persistconns.xml @@ -0,0 +1,125 @@ + + + + + The mysqli Extension and Persistent Connections + + + Persistent connection support is now present in PHP 5.3 for the + mysqli extension. Support was already present in PDO + MYSQL and ext/mysql. The 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. + + + + 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 + as is. Any cleanup would need to be done by the new + client process before it could make good use of the persistent + connection, increasing the burden on the programmer. + + + + The persistent connection of the mysqli extension + however provides built-in cleanup handling code. The cleanup carried + out by mysqli includes: + + + + + + + Rollback active transactions + + + + + + Close and drop temporary tables + + + + + + Unlock tables + + + + + + Reset session variables + + + + + + Close prepared statements (always happens with PHP) + + + + + + Close handler + + + + + + Release locks acquired with GET_LOCK + + + + + + + This ensures that persistent connections are in a clean state on + return from the connection pool, before the client process uses them. + + + + The mysqli extension does this cleanup by + automatically calling the C-API function + mysql_change_user(). + + + + 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. + + + + If you want to switch off the automatic cleanup code, you can compile + PHP with MYSQLI_NO_CHANGE_USER_ON_PCONNECT defined. + + + +