News Archive
PhpRiot Newsletter
Your Email Address:

More information

PHP @ FrOSCon: the power of mysqlnd plugins

Note: This article was originally published at Planet PHP on 23 August 2010.
Planet PHP

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 power of mysqlnd plugins

View more presentations on mysqlnd.

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 aomysqlnd_uha PECL extension. aomysqlnd_uha stands for aomysqlnd userhandlera.

class QueryLogger extends MysqlndUhConnection { public function query($res, $query) { error_log($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!