Introducing phix

Posted by Stuart Herbert on March 21st, 2011 in 1 - Beginner, phix, Toolbox.

In my Beyond Frameworks talk, I explained how a component-based architecture can help answer some of the important (i.e. expensive!) questions you might face when creating long-lived apps that rely on a PHP framework. In this series of blog posts, I’m going to look at how to go about creating and working with components.

This page has been updated with the latest information about phix.

phix is a small command-line tool for PHP applications. I created it to fix (pun intended) the problem of how to easily automate the tasks involved in creating and (especially) maintaining components. These tasks aren’t built into phix; they are commands that ship with the phix distribution. You can create your own commands to run inside phix too, and it’s easy to do so.

Installing phix

There are full installation instructions for phix on the phix project’s website.

What Can phix Do?

Running phix without any command-line parameters gives us a basic overview of what it can do:

phix 0.13.2 -
Copyright (c) 2011 Stuart Herbert and contributors
Released under the BSD license

    /usr/bin/phix [ -?dhv ] [ --? --debug --help --version ] [ -I<path> ] [ 
    --include=<path> ] [ command ] [ command-options ]

    Use the following switches in front of any <command> to have the following

    -? | -h
        display a summary of the command-line structure

    -I<path> | --include=<path>
        add a folder to load commands from

        phix finds all of its commands by searching PHP's include_path for PHP
        files in folders called 'PhixCommands'. If you want to phix to look in
        other folders without having to add them to PHP's include_path, use
        --include to tell phix to look in these folders.

        phix expects '<path>' to point to a folder that conforms to the PSR0
        standard for autoloaders.

        For example, if your command is the class '\Me\Tools\PhixCommands
        \ScheduledTask', phix would expect to autoload this class from the 'Me
        /Tools/PhixCommands/ScheduledTask.php' file.

        If your class lives in the './myApp/lib/Me/Tools/PhixCommands' folder,
        you would call phix with 'phix --include=./myApp/lib'

    -d | --debug
        enable debugging output

    -v | --version
        display phix version number

    --? | --help
        display a full list of supported commands

    help                    # get detailed help about a specific phix command
    pear:expand-package-xml # expand the tokens and contents of the
                              PEAR-compatible package.xml file
    pear:register-channels  # register the channels for the dependencies
                              listed in the PEAR-compatible package.xml file
    php-library:init        # initialise the directory structure of a
                              php-library component
    php-library:status      # check the status of a php-library component
    php-library:upgrade     # upgrade the structure of a php-library component
                              to the latest version

    See /usr/bin/phix help <command> for detailed help on <command>

phix ships with easy-to-use commands for creating and maintained packaged components of PHP code. Additional commands will be added in the future!

You can add your own commands to this list with minimal effort, something we’ll look at in a later blog post. By default, phix searches your PHP include_path for new PhixCommands namespaces to load; you can also use the -I flag to tell it to search a specific PSR-0 compatible class tree if needed.

And the best thing of all is that phix is framework-agnostic; it isn’t going to break as you upgrade or change frameworks – an important requirement for creating and working with components!


phix comes with a built-in help command to show you what any single command can do. And best of all, it automatically tells you where the code is for that command, so if something isn’t working or you want to enhance it, you don’t have to wonder where phix is getting the code from:

$ phix help php-library:init
    /usr/bin/phix php-library:init - initialise the directory structure of a
    php-library component

    /usr/bin/phix php-library:init <folder>

        <folder> is a path to an existing folder, which you must have
        permission to write to.

    This command is implemented in the PHP class:

    * Phix_Project\ComponentMaker\PhixCommands\PhpLibraryInit

    which is defined in the file:

    * /usr/share/php/Phix_Project/ComponentMaker/PhixCommands/PhpLibraryInit

Where To Find Further Information

The Phix Project website is the official homepage for the project. Hopefully you’ll be able to find everything you need from there.

Stuart’s PHP Components blog posts provide a step-by-step look at using phix to create and maintain packaged components of PHP code.


  1. Christian Weiske says:
    March 21st, 2011 at 3:46 pm

    So what exactly can I do now with phix? Where does it help me?
    Currently, it seems like a cli interface to start registered classes – like pear itself is, but that one has at least functionality built in.

  2. Wil Moore III says:
    March 21st, 2011 at 6:57 pm


    Nice component. Are you interested in receiving contributions to this project or is it closed (I didn’t see a link to the source)?

    Thanks for sharing,

    Wil Moore III

  3. Wil Moore III says:
    March 21st, 2011 at 6:59 pm

    Also, have you thought about shipping default tasks that negate the need for something like phing/ant…similar to Rake and Thor (Ruby).

  4. Stuart Herbert says:
    March 21st, 2011 at 9:19 pm

    @cweiske: phix already comes with useful commands to create skeleton PEAR-compatible packages. I’ll be looking at those in more details in the next few blog posts.

    @gggeek: SOA isn’t out of fashion, but hopefully SOAP finally is :) Would be lovely to see Zeta Components one day support PSR0. It’s time to end the autoloader-per-framework hell!

    @wil.moore: contributions are welcome – the code is on github: phix. And I definitely want to ship default tasks so that in time phing can be retired. If they’re done right, they should also provide a nice library for other phix commands.

  5. Gunnar Wrobel says:
    March 22nd, 2011 at 9:28 am

    Reminds me a lot of the Horde components tool ( I will definitely dissect your tool and try to let it influence the Horde solution. Thanks for publishing it!

  6. A semana no mundo PHP (25/03/2011) | raphael.dealmeida says:
    March 25th, 2011 at 2:01 pm

    [...] Introducing phix Phix é uma ferramenta para criação e distribuição de pacotes [...]

  7. Rune Kaagaard says:
    October 7th, 2011 at 7:53 pm

    Cutting straight to the chase. Phix helps me, in a beautiful fashion, to build framework independent code. Maintaining several large sites stuck on Drupal 6, that sounds so ensnaring. Do you have any thoughts about being PHP version independent, or even language independent? What happens when PHP 5.4 comes out and it breaks all my beautiful “independent” components? Having even a medium sized codebase, thats a serious risk. Is this in your mind not an issue, should one build ones components as web services instead, or can you offer any other advice?