<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'mysqlnd.plugin.php',
    1 => 'MySQL Native Driver Plugin API',
    2 => 'MySQL Native Driver Plugin API',
  ),
  'up' => 
  array (
    0 => 'book.mysqlnd.php',
    1 => 'Mysqlnd',
  ),
  'prev' => 
  array (
    0 => 'mysqlnd.memory.php',
    1 => 'Memory management',
  ),
  'next' => 
  array (
    0 => 'mysqlnd.plugin.mysql-proxy.php',
    1 => 'A comparison of mysqlnd plugins with MySQL Proxy',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mysqlnd/plugin.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/mysqlnd.plugin.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mysqlnd.plugin" class="chapter">
 <h1 class="title">MySQL Native Driver Plugin API</h1>
<h2>目录</h2><ul class="chunklist chunklist_chapter"><li><a href="mysqlnd.plugin.mysql-proxy.php">A comparison of mysqlnd plugins with MySQL Proxy</a></li><li><a href="mysqlnd.plugin.obtaining.php">Obtaining the mysqlnd plugin API</a></li><li><a href="mysqlnd.plugin.architecture.php">MySQL Native Driver Plugin Architecture</a></li><li><a href="mysqlnd.plugin.api.php">The mysqlnd plugin API</a></li><li><a href="mysqlnd.plugin.developing.php">Getting started building a mysqlnd plugin</a></li></ul>

 <p class="simpara">
  The MySQL Native Driver Plugin API is a feature of MySQL Native
  Driver, or <code class="literal">mysqlnd</code>. <code class="literal">Mysqlnd</code>
  plugins operate in the layer between PHP applications and the MySQL
  server. This is comparable to MySQL Proxy. MySQL Proxy operates on a
  layer between any MySQL client application, for example, a PHP
  application and, the MySQL server. <code class="literal">Mysqlnd</code> plugins
  can undertake typical MySQL Proxy tasks such as load balancing,
  monitoring and performance optimizations. Due to the different
  architecture and location, <code class="literal">mysqlnd</code> plugins do not
  have some of MySQL Proxy&#039;s disadvantages. For example, with plugins,
  there is no single point of failure, no dedicated proxy server to
  deploy, and no new programming language to learn (Lua).
 </p>
 <p class="simpara">
  A <code class="literal">mysqlnd</code> plugin can be thought of as an extension
  to <code class="literal">mysqlnd</code>. Plugins can intercept the majority of
  <code class="literal">mysqlnd</code> functions. The <code class="literal">mysqlnd</code>
  functions are called by the PHP MySQL extensions such as
  <code class="literal">ext/mysql</code>, <code class="literal">ext/mysqli</code>, and
  <code class="literal">PDO_MYSQL</code>. As a result, it is possible for a
  <code class="literal">mysqlnd</code> plugin to intercept all calls made to these
  extensions from the client application.
 </p>
 <p class="simpara">
  Internal <code class="literal">mysqlnd</code> function calls can also be
  intercepted, or replaced. There are no restrictions on manipulating
  <code class="literal">mysqlnd</code> internal function tables. It is possible to
  set things up so that when certain <code class="literal">mysqlnd</code>
  functions are called by the extensions that use
  <code class="literal">mysqlnd</code>, the call is directed to the appropriate
  function in the <code class="literal">mysqlnd</code> plugin. The ability to
  manipulate <code class="literal">mysqlnd</code> internal function tables in this
  way allows maximum flexibility for plugins.
 </p>
 <p class="simpara">
  <code class="literal">Mysqlnd</code> plugins are in fact PHP Extensions, written
  in C, that use the <code class="literal">mysqlnd</code> plugin API (which is
  built into MySQL Native Driver, <code class="literal">mysqlnd</code>). Plugins
  can be made 100% transparent to PHP applications. No application
  changes are needed because plugins operate on a different layer. The
  <code class="literal">mysqlnd</code> plugin can be thought of as operating in a
  layer below <code class="literal">mysqlnd</code>.
 </p>
 <p class="simpara">
  The following list represents some possible applications of
  <code class="literal">mysqlnd</code> plugins.
 </p>
 <ul class="itemizedlist">
  <li class="listitem">
   <span class="simpara">
    Load Balancing
   </span>
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      Read/Write Splitting. An example of this is the PECL/mysqlnd_ms
      (Master Slave) extension. This extension splits read/write queries
      for a replication setup.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Failover
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Round-Robin, least loaded
     </span>
    </li>
   </ul>
  </li>
  <li class="listitem">
   <span class="simpara">
    Monitoring
   </span>
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      Query Logging
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Query Analysis
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Query Auditing. An example of this is the PECL/mysqlnd_sip (SQL
      Injection Protection) extension. This extension inspects queries
      and executes only those that are allowed according to a ruleset.
     </span>
    </li>
   </ul>
  </li>
  <li class="listitem">
   <span class="simpara">
    Performance
   </span>
   <ul class="itemizedlist">
    <li class="listitem">
     <span class="simpara">
      Caching. An example of this is the PECL/mysqlnd_qc (Query Cache)
      extension.
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Throttling
     </span>
    </li>
    <li class="listitem">
     <span class="simpara">
      Sharding. An example of this is the PECL/mysqlnd_mc (Multi
      Connect) extension. This extension will attempt to split a SELECT
      statement into n-parts, using SELECT ... LIMIT part_1, SELECT
      LIMIT part_n. It sends the queries to distinct MySQL servers and
      merges the result at the client.
     </span>
    </li>
   </ul>
  </li>
 </ul>
 <p class="simpara">
  <strong>MySQL Native Driver Plugins Available</strong>
 </p>
 <p class="simpara">
  There are a number of mysqlnd plugins already available. These
  include:
 </p>
 <ul class="itemizedlist">
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_mc</strong> - Multi Connect
    plugin.
   </span>
  </li>
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_ms</strong> - Master Slave
    plugin.
   </span>
  </li>
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_qc</strong> - Query Cache
    plugin.
   </span>
  </li>
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_pscache</strong> - Prepared
    Statement Handle Cache plugin.
   </span>
  </li>
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_sip</strong> - SQL Injection
    Protection plugin.
   </span>
  </li>
  <li class="listitem">
   <span class="simpara">
    <strong>PECL/mysqlnd_uh</strong> - User Handler
    plugin.
   </span>
  </li>
 </ul>
 
 
 
 
 
</div>
<?php manual_footer($setup); ?>