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

PHPNW10: Friday Social

Posted by Stuart Herbert on October 18th, 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 the best of my shots from the pre-conference socials on the Friday night before the conference.

PHPNW10 Friday Social

PHPNW10 Friday Social

PHPNW10 Friday Social

PHPNW10 Friday Social

PHPNW10 Friday Social

PHPNW10 Friday Social

PHPNW10 Friday Social

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 »

Tonight’s meeting of the PHP SouthWest User Group will be at The Third Floor, Bush House, Bristol from 7pm. We’ll be in the conference room for an hour, and then from 8pm downstairs in the bar at the Arnolfini.

What Is Planned

There were quite a few of us at last weekend’s excellent PHP North West 2010 conference. Tonight, we’ll discuss the talks we attended and share what we liked and what we learned.

How To Get There

We’ll be at Bush House, 72 Prince Street, Bristol BS1 4QD. This Google Map has directions if you’re walking from Bristol Temple Meads Railway Station.

When you get to the entrance for Bush House, you’ll need to press the bottom buzzer (marked ‘The Hub’) to gain access.

How To Get Involved

Please join the PHPSW Google Group and say hello!

Be the first to leave a comment »

The first meeting of the PHP SouthWest User Group will be at The Third Floor, Bush House, Bristol from 7pm. The room is booked (big thanks to Del for that), and we have a projector sorted too; now we just need our first speakers 🙂

What Is Planned

As this is the very first meeting, our agenda is still being pulled together, but I’m hoping that Bitterman will treat us all to a rehearsal of his upcoming talk for the PHPNW10 conference in Manchester in early October. I’m looking for backup speakers just in case, and of course for anyone who wants to speak at next month’s meetup.

We’ll be at The Third Floor until 8pm, after which we’ll move into one of the local pubs (probably the Watershed) for the social half of the meet-up.

How To Get There

We’ll be at Bush House, 72 Prince Street, Bristol BS1 4QD. This Google Map has directions if you’re walking from Bristol Temple Meads Railway Station.

When you get to the entrance for Bush House, you’ll need to press the bottom buzzer (marked ‘The Hub’) to gain access.

If we like the place, I can get a discount (thanks to Del) for a regular booking.

How To Get Involved

Please join the PHPSW Google Group and say hello!

Be the first to leave a comment »

Setting Up A PHP Southwest UK User Group

Posted by Stuart Herbert on August 19th, 2010 in News.

London and the North West of the UK have their own successful PHP user groups … and it’s time we had one here in the South West 🙂

I’ve setup a PHP SW group on Google to get us started, and we’re already talking about where (probably the centre of Bristol) and when to have our first meet-up. Why not join the group and the discussion?

I’m hoping to appeal to folks using PHP who live or work in the Bristol, Bath, South Wales and South West of England regions to come along and join in. There must be plenty of us in the area!

Be the first to leave a comment »

Here’s a quick question for the wider PHP programming community … if you’re writing code that tests for the presence of an array, should is_array() also accept objects that behave like arrays?

[code lang=”php”]
$testObject = new ArrayObject(array(‘Tom’));
$testResult = is_array($testObject);
[/code]

On PHP 5.3.2, $testResult gets set to false. If you wanted to get an object that behaves like an array past this sort of test, you’d have to write:

[code lang=”php”]
$testObject = new ArrayObject(array(‘Tom’));
$testResult = (is_array($testObject) || $testObject instanceof ArrayAccess);
[/code]

I’m just curious as to what other PHP programmers think of this. Having to write the second test is longer, and there seems to be little or no benefit gained by having to do so.

What do you think?

Be the first to leave a comment »

We’re Hiring

Posted by Stuart Herbert on July 19th, 2010 in PHP In Business.

I’m looking for a PHP developer to fill a permanent web team lead developer & team leader role, based in Bath in the UK. The role is with Gradwell, a multi-award winning provider of business internet services (we’re also one of the top 50 fastest growing UK tech companies according to Deloitte), reporting directly to me in the Engineering department. We have some exciting projects (including a public-facing API) to deliver and the usual challenges of morphing legacy code to solve.

If you’re interested, drop me a line at the office (stuart.herbert at gradwell dot com) to get more details and explain why you’d be worth an interview 🙂

No agencies, thanks.

Be the first to leave a comment »

There’s a programming style I rarely see in the PHP world, but one which I use from my C programming days – programming by contract. It’s a very useful technique for writing code that is demonstrably robust, and a useful compliment to unit testing with PHPUnit.

At it’s most basic, programming by contract can be summed up as:

  • Does my function or method have inputs that are acceptable to me?
  • Has my function or method generated return data that I’m happy to pass back.

PHP has the assert() method to help with this, but it is deficient and best avoided. I’d like to share the approach I’m currently using for this, to get constructive feedback on how to evolve the style further.

At the heart of this approach lies the constraint. It is a test that must be satisfied; a bit like a runtime unit test. We could do this inline:

[code lang=”php”]
function breakMe($inputData = “I am bad data”)
{
// enforce our constraint
if (!is_array($inputData))
{
throw new Exception(‘Bad data $inputData; expected array()’);
}
}
[/code]

… but the problem with that is that it quickly bulks out your code with a lot of repetitive (and avoidable) content. An ideal candidate to make into a function or a method, which could yield:

[code lang=”php”]
function constraint_mustBeArray(&$testData)
{
if (!is_array($testData))
{
throw new Exception(“Constraint failed”);
}
}

function breakMe($inputData = “I am bad data”)
{
// our constraint is now in a nice function
constraint_mustBeArray($inputData);
}
[/code]

Here, we are trading performance (the cost of a function call) for both developer efficiency and reduced future maintenance costs. In general, the trade-off is worth it; most PHP developers work on small sites where developers are more expensive than runtime costs (within reason). The time saved from proving that code is working (and bailing immediately we prove otherwise) is worth saving.

We’re also introducing an important principle: there’s no return value to check. If execution continues on the line below the call to constraint_mustBeArray(), we can assume that the constraint was passed. If the constraint failed, we let whatever exception handlers there are, well, handle it.

There’s a couple of problems with this style that have been nagging me. It has a lot of advantages, and is probably good enough, but …

  • There’s no autoload support in PHP for functions, making it a pain to work with a large number of functions in an app or framework. Life is easier if the constraints are defined as object methods instead.
  • There’s limited potential to re-use constraints once they have been defined. They have to be explicitly called. It would be great if they could be passed into (say) a data model layer of some kind as parameters, to assist in data integrity checking. (Note the common thread of making sure that bad data is detected as early as possible, and pro-actively rejected by the app).

This led me to a more OO style:

[code lang=”php”]
class MyFramework_Array
{
static public function mustBeArray(&$testData)
{
if (!is_array($testData))
{
throw new Exception(‘Constraint failed’);
}
}
}

function breakMe($inputData = “I am bad data”)
{
// constraint is now in a reusable object method
MyFramework_Array::mustBeArray($inputData);
}
[/code]

Well, it is object-oriented for sure, but it still isn’t reusable … but it could be with lambda functions …

[code lang=”php”]
class MyFramework_Array
{
static public function mustBeArray(&$testData)
{
// create the lambda function
$constraint = function($testData)
{
if (!is_array($testData))
{
throw new Exception(‘Constraint failed’);
}
};

if ($testData !== null)
{
$constraint($testData);
}
else
{
return $constraint;
}
}
}

function breakMe($inputData = “I am bad data”)
{
// we can still call the constraint as before …
MyFramework_Array::mustBeArray($inputData);

// … but we can now also do the following …
$constraint = MyFramework_Array::mustBeArray();
$constraint($inputData);
}
[/code]

This approach gives us the flexibility of both worlds … a constraint method that we can call directly, and also a constraint function that we can assign to a variable to re-use as appropriate.

There’s still a couple of weaknesses with this approach, the most obvious one to me that finding these constraint methods is no longer quite as easy (you need to know which class they are defined on), but the counter-argument is that this is why frameworks have to rely on convention.

We’re quite heavily constrained by PHP’s syntax and parser limitations here, specifically the lack of macros (which could avoid runtime costs in production environments) and that we can’t assign lambda functions to class properties at declaration time.

I’m wondering how this style of declaring constraints could be refined further. You can take it as given that we would normally throw something other than Exception. Comments welcome 🙂

Be the first to leave a comment »

Gearman is a lightweight, high-performance solution for farming out processing work from one machine to another. I’m currently looking at using Gearman as a key part of the architecture of a new web API that I’m doing the R&D for. (I’ll go into why I need something like this, and why I’ve chosen Gearman in particular, another day).

Getting Gearman up and running on Ubuntu 9.10 (Karmic Koala) is very straight-forward and only takes a few minutes, but oddly not clearly documented on Gearman’s own wiki at the time of writing.

  1. Add “ppa:gearman-developers/ppa” as a software source.
  2. sudo apt-get install gearman-job-server
  3. sudo apt-get install libgearman-dev
  4. sudo apt-get install uuid-dev
  5. pecl install “channel://pecl.php.net/gearman-0.6.0”
  6. Add a gearman.ini to /etc/php5/conf.d, with “extension=gearman.so” as the contents
  7. sudo /etc/init.d/apache2 restart
  8. Check phpinfo() to make sure gearman extension loaded

You’ll find that the gearmand process is already up and running, and listening on port 4730 on localhost. All you need to do now is to write some code to take advantage of it 🙂

Be the first to leave a comment »

A recent El Reg article about trends in the PHP community caught my eye yesterday morning. The headline is about Zend’s depressing statistic that the majority of PHP developers do their development on Windows these days (which I’m assured by Marco is old news) … and that’s worth talking about at some point, but it isn’t what interested me the most.

As reported by El Reg, Zend’s survey results show that “seventy per cent use Zend’s Studio or Eclipse PHP Developer Tools, while 18 per cent use Vim.”

This isn’t a case of Zend making wild claims though, just less than full reporting by El Reg this time around. Zend’s own press release make it crystal clear that these are the results of a survey conducted across the Zend Framework developer community; most likely (but not directly attributed) the 2009 survey. That they haven’t released the breakdown for Zend Studio vs Eclipse PDT is perhaps telling, but still, the real headline should be:

In its own community, Zend is being very successful at convincing its community members to use multiple Zend products.

Zend’s “full-stack” strategy is starting to yield results, and it looks like Zend Framework might have been the missing component that held back their earlier attempts. The whole stack has been refreshed, true (Zend Studio now runs on Eclipse, Zend Core has folded into Zend Platform, which itself has the new and far-better-architected Zend Server positioned below it), but with Zend Framework, Zend are (imho) now able to appeal to the sort of developer communities who are willing to pay Zend’s prices. And Zend Framework is finally a product that third parties can make money from, making Zend a little more relevant in the daily lives of your average PHP developer. (I’m a great believer that a key component of all really successful products is that third parties can make money off it, not just the original creator / provider).

Now, if only Zend had an outreach programme for making Zend Server suited both technically and commercially for ISPs like where I work to consider adopting for their shared hosting and VPS customers …

Be the first to leave a comment »

By now, you might have heard the details of HipHop, Facebook’s PHP-to-C++ convertor that was announced yesterday. Like most of you, I’m eagerly awaiting the release of the code so that I can play with it and learn in detail what it can do and what it can’t. For now, Marco’s post seems to have the most technical information in it so far.

I’m with Sebastian on this one. Whether or not you think Facebook’s HipHop is relevant to you, I think they deserve credit for having shared their particular solution with the wider community. (They’ll get extra credit when they actually release some code 🙂 ) After all, they’ve built on top of open-source in the first place; giving something back to the community is part and parcel of being a good member of the community.

How many of you earn your living from open-source, but have never contributed anything back?

But that isn’t really what I want to blog about today.

I’ve been following the chat on Twitter about HipHop, and I think all the nay sayers have been overlooking an important point. HipHop has the potential to reduce the amount of power consumed in running a website. And surely that can only be a good thing for all of us?

If you don’t run your own servers in a data centre (for example you use a virtual server, or host on a shared hosting solution), then perhaps you might not be aware that the power required by each server in a rack is often a major factor in the overall cost of running the servers. Whether or not you believe in climate change, energy prices are on the rise. Whether or not you believe in peak oil, oil and natural gas supply issues are forecast to push energy prices up further. Taking steps to get more work done per unit of power consumed has been the focus of hardware manufacturers for several years now. Isn’t it time it also was the focus of the software community too?

CPU usage is only one aspect of the total power consumed by a server in a rack, but in my experience people tend to add more servers to their solution primarily because they need more CPUs running their web servers to handle more traffic. A reduction in the number of CPUs required will translate into a reduction of the number of servers required … which means a reduction in the amount of energy being consumed.

How can that not be a good thing, if it can be achieved?

I know the answer will be that PHP apps are not CPU-bound, that they spend much of their time waiting for results from the database. That might be true if you’re measuring a PHP app from the point of view of elapsed time, but what if you’re measuring the PHP app in terms of CPU cycles consumed? Every single PHP script has to run on a CPU, and has to get to the point where it’s sat waiting for the database. If HipHop means that each PHP script uses less CPU to get to the same point, that has to be a step in the right direction.

Until we can play with HipHop ourselves, it’s impossible to say whether it saves enough CPU cycles to allow us to use less CPUs and therefore less servers. Remember, you’ve still got the overhead of your operating system and web server to factor into the equation. And then there’s the energy cost of compiling your code in the first place during development; for seldom-visited websites, HipHop may increase overall energy requirements.

But it sure is nice to hope, isn’t it?

Be the first to leave a comment »
Page 11 of 19« First...910111213...Last »

This Month

October 2018
M T W T F S S
« Sep    
1234567
891011121314
15161718192021
22232425262728
293031