Using Persistent Storage with Gearman

I’m using gearman for the first time in a new project, and two things in particular were bothering me. Firstly, there doesn’t seem to be a built-in way to see what’s in the queue. Secondly, if the gearman server dies (which seemed quite likely when I was first getting to grips with this stuff and writing really buggy code!) you lose your queue. Therefore I decided that I would switch gearman over to running with persistent storage. Continue reading

Ideas of March

You may find that you read a few of these posts today – the title is a play on the fact that today is the Ides of March, and the story goes like this:

I’m seeing increasing numbers of my friends and peers announcing that blogging is coming back into fashion, which came as a surprise to me since I didn’t realise it had gone out of fashion and I’ve been blogging regularly without realising how uncool that was! With twitter managing to annoy everyone in the last week or so either with a new client, bad behaviour towards existing 3rd party clients, or reassigning twitter names, change is in the air.

Personally I like to blog, it’s a platform that I control, and I’m always too verbose for 140 character limits (which is a nice way of saying that I talk too much – if you’ve met me in person then you knew that already!). The blogs, and perhaps more importantly their comments, are the best way I know of sharing ideas and having those accessible and grouped together if you want to refer back to them at any point in the future. They are also wonderfully asynchronous; I see some great posts coming past about technologies that I don’t use, then find myself reading those articles a few months later when I’m onto the next project. Having the various blog posts, even those short ones that people think “don’t qualify” or “aren’t good enough”, really help me get started with something new – and I try to leave the same trail on my own blog and in the comments of others’ when I’m figuring things out that I think others might come up against later (where “others” includes me, if I have slept since writing the blog post!).

So – will you join us? Will pledge to blog, or to comment on blogs, in March? Here’s to a revival of blogging (and some continuation from those of us who fail at being with the cool crowd!)

Github To Jira Bug Migration Script

Recently I mentioned the github API and retrieving issues from it. This is because the joind.in project agreed to move its issue tracking from github to JIRA, since the issue tracker on github is far from feature complete. I migrated only our open issues, and comments (and the comments ended up a bit weirdly formatted on the other end but this was the best they could do). It was nothing pretty or clever but in case it’s useful to someone else, here’s the script:

Continue reading

The PHP Community Conference

Next month, I’ll be heading out to Nashville for the PHP Community Conference. This is wildly exciting for a few reasons; this is the first in what I hope will be many episodes of this event, and I’m speaking in a lineup that blows every other conference schedule I’ve seen out of the water. I have met and hung out with enough of these people to know that I’m going to get smarter just by being there! I love watching the industry leaders discuss technology, I learn so much, and I know that this event will be a fabulous opportunity for that.

The event is entirely community organised and run, rather than being backed by an organisation. I am a great believer in having events come from the community that wants to attend them, and as an organiser (both for community and organisation-backed events) myself, the freedom to do things that will really work, rather than things that can be agreed by a management committee, makes the difference between a good event and a great one. What’s different about this PHP Community Conference is that most of the organisers are speakers and attendees of some of the biggest conferences in the PHP world … and they’ve built the international-level conference *they* want to attend!

The lineup is nothing short of stellar, these guys and gals would be the main feature at most of the other PHP-specific events I’ve been to, in fact three or four of them have been keynotes at other events I’ve attended. I’m speaking myself, which was wildly exciting from the moment I got the acceptance email right up until the rest of the schedule was published … and is now slightly daunting, in the best possible way! I’m giving a half-day tutorial on Web Services, covering all the theory points and showing you how to not only consume but also publish your own services. I work so much with APIs and being able to take the time to properly share my experiences so others can go on to build their own kick-ass services is something really special.

I can’t wait to get out to Nashville on April 21/22 and meet the speakers and the fantastic crowd of attendees that I know an event like this will draw. Which is not to say that there are not other great conferences, but I’m really looking forward to seeing something special in Nashville … I sincerely hope to see you there!

Dealing with MySQL Gone Away in Zend Framework

I wrote recently about having gearman in my application, however I have been seeing problems with the long-running PHP worker scripts. My logs had entries like this:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

The worker is a Zend Framework application, run from the CLI, and it seemed like the Zend_Db_Adapter had no way of knowing when MySQL had let go of its end of the connection. I tried a few different things, including Zend_Db_Adapter::getConnection(), but without success – until I dug through the source code (with some help from a friend) and realised that ZF was not reconnecting at all if it thought it already had a connection. So instead, I expressly disconnected and reconnected the database handler. At bootstrap time, I place my database handle into the registry, so I simply added this at the start of the actual function that the gearman worker calls:

$db = Zend_Registry::get('db');
$db->getConnection();

At the end of my script, before it returns to the loop waiting for another gearman job, I just disconnect my database:

$db->closeConnection();

Now Zend_Db_Adapter knows that when I ask it to connect, it needs to go off and make a new connection, and everything works really well! I was seeing the errors because I’m still only testing the system so it can go days between getting any new jobs, and the timeout on MySQL is shorter than that.

A Tale of Two User Groups

This post is probably only relevant if you’re interested in PHP and UK-based. In the next few weeks I’ll be at some user groups that I don’t manage to visit often. On Thursday, 3rd March, I’ll be at PHP East Midlands to talk about Design Patterns. On Tuesday, 12th April, I’ll be at PHP West Midlands, also speaking but this time about OAuth. I may make it to one or other of PHPNW and LeedsPHP user groups in that time as well … and all of those are within 2 hours’ driving of my home! PHP is alive and well where I live, my great respect and thanks goes to all the community leaders who make these groups happen – thank you all :)

PHP Days and PHP Unconference Europe

I spend most of the last week or so over in Manchester for a combination of excellent PHP-related events: PHP Unconference Europe on Saturday and Sunday (with a rather excellent warm-up party on Friday night!), followed by the PHP Days training on Monday and Tuesday.

PHP Unconference Europe

A large crowd gathered very early on Saturday morning at the Pitcher and Piano, and got our briefing on how session voting works (everyone gets 4 stickers, you stick the stickers onto the sessions you want to see, the ones with the most get scheduled).
DSCF4430.JPG

Continue reading

Mercurial Primer

I am a source control nut, I’ve been speaking about Subversion for years, I co-lead an active open source project which uses git and GtiHub, and I’ve also dabbled with Bazaar. So far I’m feeling the limits of Subversion, loving the code-hosting features of some of the DVCS tools, and hating git and github in equal measure (don’t bother to try to talk me out of this, I’m well aware the problems are mostly on my side). I don’t know anyone else using Bazaar in the PHP community but I do know quite a few people raving about Mercurial, or Hg. This post is a quick introduction to the commands I have been using since I started trying out Hg and BitBucket for myself.

Continue reading

Using Gearman from PHP

I’ve introduced Gearman into a project I’m working on, and since a few people have asked I thought I’d share my experiences. Basically, this application generates some PDFs from a variety of data sources, makes images, and emails it. Since the whole data processing, image handling, PDF generation process is fairly heavy, I’m putting the requests to generate these onto a gearman queue and having some workers process the jobs. The eventual aim is to bring up EC2 instances (or php-specific cloud hosting perhaps? Recommendations gratefully received!) to do this work but right now I have one worker and it’s all on one server.

Continue reading

Callbacks in PHP

Recently I was working on something and I wanted to call an object method as a callback, but got confused when I realised the method had been caused statically. This was caused by my inability to RTFM and I wondered how I’d come so far without actually coming across the many and varied things you can pass into any place a callback is needed. I think we’ve all seen a function callback; something like this:

function myExcitingFunction() {
  // do something remarkable
}

call_user_func('myExcitingFunction');

You can also call methods of objects rather than just plain functions, and this is where I tripped myself up.
Continue reading