Pagoda Box – scalable platform for your PHP application

I got my hands on a private beta of Pagoda Box.  It is a platform that you can deploy your PHP applications to.   I gave it a brief look around and I have to say it’s pretty sweet.

Right after you register and get access to your dashboard, you can add applications.  Applications are cloned from GitHub repositories.  Both public and private repositories are supported.  Once you add an application, you can access it at http://your-app-name.pagodabox.com. If you’d rather have your own domain – you can assign it to your application from the dashboard and all that will remain to be done is adding an A-record in your DNS zone.  Super easy!

There is more to it, even at this beta stage.  Pagoda Box supports a number of PHP frameworks, including all major ones – CakePHP, CodeIgniter, Lithium, Symfony, Zend, and more.  You can also optionally have a MySQL database for your application.  They even help you out with outgoing email.

On top of that, you have control as to how many instances of the application you want (the more you have, the more requests you can serve at the same time, and the more you’ll have to pay).  There are statistics of your application performance, requests, and a few other parameters (I’m sure those will grow together with the project).

I’ll admit, I am too used to hosting my projects on my own servers to take immediate advantage of Pagoda Box.  But I am now seriously considering which projects I can move out of my server and into this platform.  It just makes things so much easier.  Deploying and re-deploying works wonders for any GitHub commit of your project.  Initial resources that one usually needs to try an idea out are free of charge.  If the idea picks up, the prices are more than reasonable (and comparable to other hosting solutions).

Out of those things that I consider necessary, I haven’t see any mentioning of files (uploaded via application, for example), support for build systems (such as Phing), and some sort of common library of frequently used code (PEAR modules, for example).  But I’m sure that either I simply didn’t look for these hard enough, or they will be added in the future.

If you are a PHP developer or involved with PHP source on GitHub in any other way, I suggest you try it out.  You can request a private beta invite directly from Pagoda Box website.  Or, if you prefer, I can send you one (I have about 10 of them left for now).  Also watch the demonstration screencasts,  and read through other platform features.

Terminator in PHP

I’ve mentioned a few times in this blog that one particular bit I love about open source software is humor in documentation.  While most commercial applications stick to a strict, official language in their manuals, open source developers often expose their humane side with jokes, references to movies, television shows and so on.

Today I came across yet another example of that.  Not strictly in a software manual, but close enough.  Here is a partial screenshot of a comment on PHP.net website, page about get_object_vars() function.

A well places Terminator references – how cool is that!

Color Image Generator

Today, I had to create a simplistic tool for one of my side projects.  What I needed was a quick way to create an image of a specific size, filled with specific color.  If it was just for me, I could have survived with the Linux command line, of course.  But there are other, non-technical people involved.

I coded a quick prototype in PHP with ImageMagick, which I called Color Image Generator.  Once the functionality was there, I cleaned it up a bit and published to GitHub.  You can grab the sources and use them any way you like, or you can use the hosted version.  Enjoy!

Partial string replacement with fixed length in PHP

Today I came across one of those problems that look simple and straight forward at first, but then somehow consume a good part of an hour to solve.  I wanted to replace a part of the string (in the middle), with given character, without changing the length of the string itself.  Once scenario would be a credit card number, where I would want to replace all digits with an ‘x’, leaving only the first digit and the last four as they were.  I tried a number of approaches, including sscanf() and array_splice() ones.  My final version is below.  It might be somewhat longer than I expected, but I like the simplicity of it.

<?php
/**
 * Replace middle of the string with given char, keeping length
 *
 * <code>
 * print padString('1234567890123456', 1, 4, 'x');
 * </code>
 *
 * @param string $string String to process
 * @param integer $start Characters to skip from start
 * @param integer $end Characters to leave at the end
 * @param string $char Character to replace with
 * @return string
 */
function padString($string, $start, $end, $char) {
    $result = '';

    $length = strlen($string) - $start - $end;
    if ($length <= 0) {
        $result = $string;
    }
    else {
        $replacement = sprintf("%'{$char}" . $length . "s", $char);
        $result = substr_replace($string, $replacement, $start, $length);
    }

    return $result;
}
?>

P.S.: Chris posted an alternative solution. Please have a look.

MySQL prompt

I’ve been using MySQL for quite a few years by now, but only today I learned that it is possible to define MySQL prompt.  As per this blog post, all it takes is a couple of lines in .my.cnf file with something like:

[mysql]
prompt="\u@\h (\d)> "

That alone will help to prevent a gadzillion of destructive mistakes when you think that you are working with one database, when, in fact, you are working with a totally other.  On top of that, the blog post suggests using rlwrap tool, with which one could add some colors to the prompts as well.