array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'mysqlnd.persist.php', 1 => 'Persistent Connections', ), 'up' => array ( 0 => 'book.mysqlnd.php', 1 => 'Mysqlnd', ), 'prev' => array ( 0 => 'mysqlnd.incompatibilities.php', 1 => 'Incompatibilities', ), 'next' => array ( 0 => 'mysqlnd.stats.php', 1 => 'Statistics', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mysqlnd/persist.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
Using Persistent Connections
If mysqli
is used with mysqlnd
,
when a persistent connection is created it generates a
COM_CHANGE_USER
(mysql_change_user()
) call on the server. This
ensures that re-authentication of the connection takes place.
As there is some overhead associated with the
COM_CHANGE_USER
call, it is possible to switch this
off at compile time. Reusing a persistent connection will then
generate a COM_PING
(mysql_ping
)
call to simply test the connection is reusable.
Generation of COM_CHANGE_USER
can be switched off
with the compile flag
MYSQLI_NO_CHANGE_USER_ON_PCONNECT
. For example:
shell# CFLAGS="-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT" ./configure --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --enable-debug && make clean && make -j6
Or alternatively:
shell# export CFLAGS="-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT" shell# configure --whatever-option shell# make clean shell# make
Note that only mysqli
on mysqlnd
uses COM_CHANGE_USER
. Other extension-driver
combinations use COM_PING
on initial use of a
persistent connection.