<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.mysqlnd.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'mysqlnd.persist.php',
    1 => 'Persistent Connections',
    2 => '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',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mysqlnd.persist" class="chapter">
 <h1 class="title">Persistent Connections</h1>

 <p class="simpara">
  <strong>Using Persistent Connections</strong>
 </p>
 <p class="simpara">
  If <code class="literal">mysqli</code> is used with <code class="literal">mysqlnd</code>,
  when a persistent connection is created it generates a
  <code class="literal">COM_CHANGE_USER</code>
  (<code class="literal">mysql_change_user()</code>) call on the server. This
  ensures that re-authentication of the connection takes place.
 </p>
 <p class="simpara">
  As there is some overhead associated with the
  <code class="literal">COM_CHANGE_USER</code> call, it is possible to switch this
  off at compile time. Reusing a persistent connection will then
  generate a <code class="literal">COM_PING</code> (<code class="literal">mysql_ping</code>)
  call to simply test the connection is reusable.
 </p>
 <p class="simpara">
  Generation of <code class="literal">COM_CHANGE_USER</code> can be switched off
  with the compile flag
  <code class="literal">MYSQLI_NO_CHANGE_USER_ON_PCONNECT</code>. For example:
 </p>
<div class="example-contents">
<div class="cdata"><pre>
shell# CFLAGS=&quot;-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT&quot; ./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 &amp;&amp; make clean &amp;&amp; make -j6
</pre></div>
</div>

 <p class="simpara">
  Or alternatively:
 </p>
<div class="example-contents">
<div class="cdata"><pre>
shell# export CFLAGS=&quot;-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT&quot;
shell# configure --whatever-option
shell# make clean
shell# make
</pre></div>
</div>

 <p class="simpara">
  Note that only <code class="literal">mysqli</code> on <code class="literal">mysqlnd</code>
  uses <code class="literal">COM_CHANGE_USER</code>. Other extension-driver
  combinations use <code class="literal">COM_PING</code> on initial use of a
  persistent connection.
 </p>
</div>
<?php manual_footer($setup); ?>