MySQL and PHP
Copyright 1997-2021 the PHP Documentation Group.
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.