MySQLND, MySQL_UH and other goodies available to PHP programmers

January 25, 2011

News

If you don’t use MySQL then this article isn’t going to be of much interest to you. I mean you are still welcome to read it but I really want to talk to those using PHP and MySQL together because we’ve got new toys with which to play.

PHP 5.3 shipped with a new driver for MySQL, mysqlnd or MySQL Native Driver. While one of it’s biggest features is that it gives us a mysql driver that is part of PHP so it doesn’t suffer from licensing issues that the previous driver did. However, in the redesign, the architecture was changed. With shiny the new driver comes new PECL extensions that work with it, one of the most interesting seems to be PECL/mysql_uh (MySQL Userland Handler) written by David Soria Parra.

All this leads me to the article I found this morning written by Ulf Wendel. (Thanks to Michael Maclean for telling me who wrote it.) The title is “PHP: Transparent load balancing and sharding with mysqlnd”It’s a very interesting look at mysql_uh and some of the things you can do with it.

The PHP 5.3 source tree contains a PHP licensed full-fledged MySQL client library called “MySQL native driver for PHP” or short “mysqlnd”. Any of the three existing PHP MySQL extensions (mysql, mysqli, PDO_MYSQL) can make use of it. As a new development the mysqlnd library has a modular design featuring a mighty plugin interface.

The mighty plugin interface has attracted the attention of Mayflower/thinkPHP and David Soria Parra leading into the development of PECL/mysqlnd_uh (uh = user handler). By help of PECL/mysqlnd_uh it is possible to write mysqlnd plugins, the magic back boxes above, using PHP instead of C.

The author of this article presents a PHP class he wrote that hooks into the connect() method to randomly select a server from which to read. This is an example and obviously, in most cases, if you have to run multiple database server, you are going to want that code written in C and not PHP. However for prototyping, this is a very cool idea.

The article is a bit difficult to read at time but trust me, stick with them because the stuff in there is the stuff you want in your head when you are working on your next application.

BTW, I got this post from a tweet by @PierreJoye, a core contributor to PHP and really smart guy. Pierre and I disagree about lot of things, and usually vocally and publicly. However just because I disagree with him doesn’t mean I don’t respect him and his contributions to PHP. It does serve to prove the point that the PHP community isn’t defined as my little group of friends. (Don’t laugh, it’s not your little group of friends either.) :)

About Cal Evans

Many moons ago, at the tender age of 14, Cal touched his first computer. (We're using the term "computer" loosely here, it was a TRS-80 Model 1) Since then his life has never been the same. He graduated from TRS-80s to Commodores and eventually to IBM PC's. For the past 10 years Cal has worked with PHP and MySQL on Linux OSX, and when necessary, Windows. He has built on a variety of projects ranging in size from simple web pages to multi-million dollar web applications. When not banging his head on his monitor, attempting a blood sacrifice to get a particular piece of code working, he enjoys building and managing development teams using his widely imitated but never patented management style of "management by wandering around". Cal is currently based in Nashville, TN and is gainfully unemployed as the Chief Marketing Officer of Blue Parabola, LLC. Cal is happily married to wife 1.28, the lovely and talented Kathy. Together they have 2 kids who were both bright enough not to pursue a career in IT. Cal blogs at http://blog.calevans.com and is the founder and host of Day Camp 4 Developers

View all posts by Cal Evans

Comments are closed.