mysql native driver_PHP - Manual: MySQL Native Driver Plugin API (官方文档)

MySQL Native Driver Plugin API

Table of Contents

The MySQL Native Driver Plugin API is a feature of MySQL Native

Driver, or mysqlnd. Mysqlnd

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. Mysqlnd plugins

can undertake typical MySQL Proxy tasks such as load balancing,

monitoring and performance optimizations. Due to the different

architecture and location, mysqlnd plugins do not

have some of MySQL Proxy'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).

A mysqlnd plugin can be thought of as an extension

to mysqlnd. Plugins can intercept the majority of

mysqlnd functions. The mysqlnd

functions are called by the PHP MySQL extensions such as

ext/mysql, ext/mysqli, and

PDO_MYSQL. As a result, it is possible for a

mysqlnd plugin to intercept all calls made to these

extensions from the client application.

Internal mysqlnd function calls can also be

intercepted, or replaced. There are no restrictions on manipulating

mysqlnd internal function tables. It is possible to

set things up so that when certain mysqlnd

functions are called by the extensions that use

mysqlnd, the call is directed to the appropriate

function in the mysqlnd plugin. The ability to

manipulate mysqlnd internal function tables in this

way allows maximum flexibility for plugins.

Mysqlnd plugins are in fact PHP Extensions, written

in C, that use the mysqlnd plugin API (which is

built into MySQL Native Driver, mysqlnd). Plugins

can be made 100% transparent to PHP applications. No application

changes are needed because plugins operate on a different layer. The

mysqlnd plugin can be thought of as operating in a

layer below mysqlnd.

The following list represents some possible applications of

mysqlnd plugins.

Load Balancing

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.

Failover

Round-Robin, least loaded

Monitoring

Query Logging

Query Analysis

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.

Performance

Caching. An example of this is the PECL/mysqlnd_qc (Query Cache)

extension.

Throttling

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.

MySQL Native Driver Plugins Available

There are a number of mysqlnd plugins already available. These

include:

PECL/mysqlnd_mc - Multi Connect

plugin.

PECL/mysqlnd_ms - Master Slave

plugin.

PECL/mysqlnd_qc - Query Cache

plugin.

PECL/mysqlnd_pscache - Prepared

Statement Handle Cache plugin.

PECL/mysqlnd_sip - SQL Injection

Protection plugin.

PECL/mysqlnd_uh - User Handler

plugin.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值