Ulf Wendel

PHP @ FrOSCon: the power of mysqlnd plugins

Slowly the power of mysqlnd plugins becomes visible. Mysqlnd plugins challenge MySQL Proxy and are often a noteworthy, if not superior, alternative alternative to MySQL Proxy for PHP users. Plugins can do almost anything MySQL Proxy can do – but on the client. Please find details in the slides. The presentation has been given today at the PHP track at FrOSCon.

The biggest news is certainly the work from David Soria Parra. David made it possible to write mysqlnd plugins in PHP! No C coding skills needed. It can’t get any easier. Insipired by the hints given in the C mysqlnd plugin API documentation he and his employer Mayflower decided to develop the “mysqlnd_uh” PECL extension. “mysqlnd_uh” stands for “mysqlnd userhandler”.

class QueryLogger extends MysqlndUhConnection {

  public function query($res, $query) {
    return parent::query($res, $query);


mysqlnd_uh_set_connection_proxy(new QueryLogger());

Assume you have installed a PHP application and you want to know what queries it runs. Using PECL/mysqlnd_uh it is as little as the above code needed to audit the application. Install PECL/mysqlnd_uh, put the code in your auto_prepend_file and find the queries in your error log. This works with every PHP application running on PHP 5.3.3 or newer. It works without touching the application. Not having to change the application itself makes updates much easier. Whenever the application vendor releases a new version you can just install it. Your QueryLogger is not part of the application. It will continue to work after the application update.

Query logging is trivial. Even load balancing or failover should be easy to implement. Future will proof, stay tuned!

One Comment