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.)