Learn More About PHP And The Web Platform!

Struggling with your web server, or to scale your PHP application to meet growing demand?

Whether you're running one server or a whole server farm; whether you're hosting on Windows Server or on Linux.

Learn from Stuart's experience with system design, delivery, support and management to help you do a better job and have an easier time.

Beneath Whitby breakwater

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 - http://www.phix-project.org
Copyright (c) 2011 Stuart Herbert and contributors
Released under the BSD license

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

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

    -? | -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 'MeToolsPhixCommands
        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

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!

Self-Documenting

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
NAME
    /usr/bin/phix php-library:init - initialise the directory structure of a
    php-library component

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

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

IMPLEMENTATION
    This command is implemented in the PHP class:

    * Phix_ProjectComponentMakerPhixCommandsPhpLibraryInit

    which is defined in the file:

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

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.

14 comments »

Last month, I delivered my Beyond Frameworks talk at PHP UK 2011. The talk is all about the challenges that the framework-using members of the PHP community are going to face as major framework upgrades (such as Zend Framework 2 and Symfony 2) are released, and a clear strategy on what you can do to minimise these challenges in the future: build more components, don’t put all your eggs into the frameworks basket.

If you didn’t make it to my talk at PHP UK 2011, the video of the talk is now available online:

Beyond Frameworks – Stuart Herbert from PHP UK Conference on Vimeo.

You can find the slides up on Slideshare.net:

and you can download the slides as a PDF too.

(Btw, don’t forget to check out all the talks from PHP UK 2011 too …)

Thank you to everyone who left comments about my talk on joind.in. I thought it would be useful to post some answers to some of the comments.

  • I would have loved to have had time to show you how to convince your own managers of the advantages of changing architectures for the future. Not quite sure how to do that in a lecture. Might be an interesting follow-up to do at a few PHP user groups?
  • I had one commenter note that the talk spent too long explaining what a component is, whilst another commenter wished I’d provided more detail. I did test an earlier version of the talk before the conference (many thanks to everyone at #phpsw for that!), one that included code examples. The talk seemed to work best by focusing into the principles behind good components, and blog posts seemed to be the right place to get into example code.
  • Frameworks don’t suck, it’s just that you have to understand the costs involved in using a framework if your code has to live for years and years like ours does. With the need for PHP frameworks to mature and innovate, and with the way that the labour market trends shift, at some point you could find that your code has to outlive your framework of choice. That’s what happened with us. If you don’t maintain software products, which is probably the majority of the community today, then you’ve nothing to worry about either way 🙂

I mentioned code examples above, and they’re coming in my next blog post 🙂

Be the first to leave a comment »

Ideas Of March

Posted by Stuart Herbert on March 15th, 2011 in Community, Opinion.

Chris has made a timely call for everyone (especially the Twitterati) to start blogging about PHP once more. Much of our community’s interaction has moved to Twitter and conferences, and we’re simply not leaving enough longform content out there any more.

There’s a key reason why I blog less about PHP these days, though, and it has nothing to do with Twitter. Our wider community simply doesn’t read blogs any more (if they ever did). They’ve already moved on to StackOverflow, and other similar places.

This is just my experience, and we can all put it to the test:

  • Go along to your next PHP User Group, and ask for a quick show of hands for how many people there are subscribers to Planet PHP, where we’ve aggregated blogs about PHP for many years now.
  • Then, the next time you’re at a large conference, ask everyone you meet the same question.

Over the years, I’ve found that our wider community doesn’t have the time to keep up with the blogs; but when they get stuck and the excellent PHP Manual can’t help them, they hit Google (and latterly StackOverflow) for quick answers. I’m always stunned by how few people have ever heard of Planet PHP.

This is also reflected in pageview and feed analytic stats, where nearly all the traffic comes from search engine queries. Planet PHP sadly ranks at #10 in my stats; I get more views from an ajax development site, even though I’m assuredly a backend engineer.

These are just my experiences. I would welcome you sharing yours!

What does this all mean to me?

  • We all need to do much more to promote Planet PHP (offline!) as the hub for proactive developers to stay up to date with what’s going on in the world of PHP. Why Planet PHP? My apologies to those who put a lot of fantastic work into other community sites, but they don’t seem to generate any measurable traffic at all.
  • Our community values hands-on, targeted articles that describe and solve specific problems that they encounter. They go looking for such content every day, and when that fails, they resort to StackOverflow et al.
  • We need to encourage our fellow developers to make time to develop their own skills, so that they don’t have to be hitting Google to react to an avoidable problem in the first place. Encourage your friends and colleagues to create and share reading lists, or to give a talk or demonstration at their local PHP user group. Get involved with community education projects like PHP Fundamentals, so that we can create a self-educating profession.

And, above all (irony intended …) use Twitter for the opinion pieces, where the world can forget them after 4 days 🙂

8 comments »

March’s meeting of the PHP SouthWest User Group will be at The Golden Guinea in Redcliffe, Bristol, from 7pm on Wednesday 9th March.

What Is Planned

We might be getting a testing talk from Ade Slade, and we’ll also do a PHPUK 2011 round-up to share what we learned at the conference.

How To Get There

We’ll be at The Golden Guinea, 19 Guinea Street, Bristol BS1 6SX. It’s a short walk from Bristol Temple Meads Railway Station if you’re coming by train.

How To Get Involved

Please join the PHPSW Google Group and say hello!

Be the first to leave a comment »

PHPUK 2011 Talk: Beyond Frameworks

Posted by Stuart Herbert on February 25th, 2011 in Conferences.

I’ve just finished giving my talk at this year’s excellent PHP UK 2011 conference, on how to use code frameworks like Zend Framework and Symfony without them holding your code hostage. Here are my slides from the talk:

This talk is a follow up to my successful PHPUK 2009 about what it can be like to live with frameworks when you do product development. Looking back on that talk now, it’s interesting to see how some of the themes from two years ago have changed as the business enjoyed two straight years of record growth.

If you were at the conference, and attended the talk, I’d love to read comments about how I did on joind.in.

Be the first to leave a comment »

I post photos to Flickr from time to time, and then write blog articles about the photos. The blog articles get written days, weeks, sometimes months in advance of when they’re scheduled to appear on my blog … which makes it a tad difficult to add a link from a photo to all of the blog articles that mention it.

So a couple of weekends ago I knocked up a very crude script that uses the Flickr API (via phpFlickr) to work through all of the published blog posts and make sure each of my Flickr photos has links back to each blog post that mention it. I’m posting it here in the public domain. Hopefully someone will find it a useful starting point to do something similar for their own blog.

[code lang=”php”]

<?php

require_once('phpflickr-3.0/phpFlickr.php');

$flickrApiKey = '’;
$flickrSecret = ”;
$flickrToken = ”;

$f = new phpFlickr($flickrApiKey, $flickrSecret);
$f->setToken($flickrToken);
$f->enableCache(‘fs’, ‘/tmp’, 3600);

// first step – find the first published blog post
$url = ‘http://blog.stuartherbert.com/photography/’;
$rawHtml = file_get_contents($url);
preg_match(‘/

/’, $rawHtml, $matches);

$blogPosts = array();
$flickrPhotos = array();

$latestPost = $matches[1];
$nextPost = $url . ‘?p=’ . $latestPost;

function updatePhotos($photoIndex, $flickrPhotos, $blogPosts, $f)
{
foreach ($photoIndex as $photoId => $flickrPhoto)
{
// we must rewrite the description
preg_match(‘|(.*)Copyright |s’, $flickrPhoto[‘description’], $matches);
if (isset($matches[1]))
{
$description = $matches[1];
}
else
{
$description = ”;
}
$description .= ‘Copyright (c) Stuart Herbert. Blog | Twitter | Facebook‘ . “n”
. ‘Photography: Merthyr Road | Daily Desktop Wallpaper | 25×9 | Twitter.’ . “nn”;

if (count($flickrPhoto[‘blogPosts’]) == 1)
{
$description .= ‘Want to know more about this photo? See this blog entry:’ . “nn”;
}
else
{
$description .= “Want to know more about this photo? See these blog entries:nn”;
}

foreach ($flickrPhoto[‘blogPosts’] as $postUrl => $blogPost)
{
$description .= ‘* ‘ . $blogPost[‘title’] . “n”;
}

// description is made … now to upload it
echo “Photo: ” . $photoId . ‘ :: ‘ . $flickrPhoto[‘title’] . “n”;
echo “URL : ” . $flickrPhoto[‘url’] . “n”;
echo “Old : ” . $flickrPhoto[‘description’] . “n”;
echo “New : ” . $description . “n”;

echo “nPushing changes to Flickr …”;
$f->photos_setMeta($photoId, $flickrPhoto[‘title’], $description);
echo ” donen”;
}
}

while ($nextPost !== null)
{
$photoIndex = array();

echo “Downloading $nextPost …”;
$rawHtml = file_get_contents($nextPost);
echo ” donen”;
if (!$rawHtml)
{
die(“Unable to download HTML for URL: ” . $nextPost . “n”);
}

preg_match(‘|

.*(.*)|Us’, $rawHtml, $matches);
$postUrl = $matches[2];
$title = $matches[3];
echo “Blog post title is: $titlen”;
echo “Blog post url is: $postUrln”;

preg_match(‘||’, $rawHtml, $matches);
if (isset($matches[1]))
{
$nextPost = $matches[1];
}
else
{
$nextPost = null;
}

preg_match(‘|

(.*)

|Us’, $rawHtml, $matches);
if (!isset($matches[1]))
die(“regex failed againn”);
$entryHtml = $matches[1];

preg_match_all(‘|(http://www.flickr.com/photos/stuartherbert/[0-9]+/)”|’, $entryHtml, $matches);
$blogPosts[$postUrl][‘url’] = $postUrl;
$blogPosts[$postUrl][‘title’] = $title;
$blogPosts[$postUrl][‘matches’] = $matches;

foreach ($matches[1] as $flickrPhoto)
{
$parts = explode(‘/’, $flickrPhoto);
$photoId = $parts[count($parts)-2];
$photoInfo = $f->photos_getInfo($photoId);

$flickrPhotos[$photoId][‘url’] = $flickrPhoto;
$flickrPhotos[$photoId][‘title’] = $photoInfo[‘title’];
$flickrPhotos[$photoId][‘description’] = $photoInfo[‘description’];
$flickrPhotos[$photoId][‘blogPosts’][$postUrl] = $blogPosts[$postUrl];

// note the photos we need to update because we have
// seen this post
$photoIndex[$photoId] = $flickrPhotos[$photoId];

echo “- Photo: ” . $photoInfo[“title”] . “n”;
}

updatePhotos($photoIndex, $flickrPhotos, $blogPosts, $f);
}

echo “nn”;
echo “Photo scraping complete!!nn”;

// when we get to here, we have photos to go and update on flickr
?>
[/code]

1 comment »

February’s meeting of the PHP SouthWest User Group will be at The Golden Guinea in Redcliffe, Bristol, from 7pm on Wednesday 9th February.

What Is Planned

I’m speaking at the PHP UK conference later in February, and will be practising my talk. No guarantees, but I think Rob Allen might be practicing his talk too.

How To Get There

We’ll be at The Golden Guinea, 19 Guinea Street, Bristol BS1 6SX. It’s a short walk from Bristol Temple Meads Railway Station if you’re coming by train.

How To Get Involved

Please join the PHPSW Google Group and say hello!

Be the first to leave a comment »

PHPNW10: Conference Audience

Posted by Stuart Herbert on October 21st, 2010 in #phpnw, Conferences.

Another year, another great PHP North West conference organised by Jeremy Coates and his team at Magma Digital and the PHP North West User Group.

This year, I went along with my camera to try my hand at conference photography for the first time, in between attending plenty of great talks. These are my best shots of the audience from Track 1 (there were three tracks in total) in the main auditorium.

Conference Audience

Conference Audience

Conference Audience

Conference Audience

Conference Audience

These are my last shots from the conference. I hope you’ve enjoyed them. I’ve also posted my thoughts on being a first-time conference photographer over on my photography blog.

Copyright (c) Stuart Herbert. Blog | Twitter | Facebook
Photography: Merthyr Road | Daily Desktop Wallpaper | 25×9 | Twitter.

Be the first to leave a comment »

Another year, another great PHP North West conference organised by Jeremy Coates and his team at Magma Digital and the PHP North West User Group.

This year, I went along with my camera to try my hand at conference photography for the first time, in between attending plenty of great talks. These are my best shots of the speakers from Track 1 (there were three tracks in total) in the main auditorium.

Lorna Mitchell

Rob Allen

Rob Allen

Ian Barber

Ian Barber

Marco Tabini

Harrie Verveer

Derick Rethans & Rob Allen

Marcus Deglos

Marcus Deglos & David Zuelke

David Zuelke

I’ll post my last shots from the conference tomorrow. I’ve also posted my thoughts on being a first-time conference photographer over on my photography blog.

Copyright (c) Stuart Herbert. Blog | Twitter | Facebook
Photography: Merthyr Road | Daily Desktop Wallpaper | 25×9 | Twitter.

Be the first to leave a comment »

PHPNW10: Jeremy Coates

Posted by Stuart Herbert on October 19th, 2010 in #phpnw, Conferences.

Another year, another great PHP North West conference organised by Jeremy Coates and his team at Magma Digital and the PHP North West User Group.

This year, I went along with my camera to try my hand at conference photography for the first time, in between attending plenty of great talks. These are my best shots of Jeremy Coates, who led the organising effort for the conference.

Jeremy Coates

Jeremy Coates

Jeremy Coates

There’ll be more shots from the conference tomorrow. I’ve also posted my thoughts on being a first-time conference photographer over on my photography blog.

Copyright (c) Stuart Herbert. Blog | Twitter | Facebook
Photography: Merthyr Road | Daily Desktop Wallpaper | 25×9 | Twitter.

Be the first to leave a comment »
Page 10 of 19« First...89101112...Last »