Category: Me

Slim's route cache file

When you have a lot of routes, that have parameters, consider using the router's cache file to speed up performance.

To do this, you set the routerCacheFile setting to a valid file name. The next time the app is run, then the file is created which contains an associative array with data that means that the router doesn't need to recompile the regular expressions that it uses.

For example:

Note that there's no invalidation on this cache, so if you add or change any routes, you need to delete this file. Generally, it's best to only set this in production.

As a very contrived example to show how it works, consider this code:

This application creates 25 groups, each with 4000 routes, each of which has a placeholder parameter with a constraint. That's quite a lot of routes, but things take long enough that we can see timing. The App\Action does nothing.

On my computer, using PHP 7.0.18's built-in web server, the first time we run it, we see this:

This took 2.7 seconds to execute. At the same time, it also created a file called routes.cache.php which is then used for the next run:

This time, it took just 263ms.

That's a big difference!

If you have a lot of complex routes in your Slim application, then I recommend that you test whether enabling route caching makes a difference.

2016 in pictures

Another year has passed which gives me an excuse to to reflect on what's happened. As usual, I look at the photos that I've taken and frame my thoughts around them.

January

At the very end of January I visited Phoenix, Arizona to see Evan, Priscilla & other friends. I also attended FOSDEM again and spent a tourist day in Brussels.

The Europeans insisted on seeing the sun!Atomium


February

I was fortunate enough to speak at PHPUK again in February.

The conference is about to startStart of the second day

March

The highlight of March was visiting the NYMR to see Flying Scotsman.

Flying Scotsman from the linesideUp close

April

In April, my eldest drove a Lamborghini and now intends to buy one! It's important to be able to dream when you're 14. I also visited the NRM.

Eldest drove a Lamborghini!Mallard

May

May is the month of birthdays in our household. I also attended the StatusCode event in Nottingham

Happy Birthday!Andrew


June

Two conferences in June. I spoke at PHP South Coast and took my favourite photo of Andrew Smith ever! I also attended Lead Developer.

Best pose everMichael Lopp

July

July was the inaugural UK edition of REST Fest in Edinburgh. We also went on holiday where I attempted sunrise photos and ate lots of ice cream.

Mike talks about Conway's four lawsSunrise

August

Worcester Comic Con happened in August where we got to meet "our" Doctor! Unfortunately this was also the month when my dad was taken ill.

Georgina with her DoctorLearning table top gaming

September

September was about family and friends with an extended family gathering and a trip to Leeds to see friends. Dad was transferred to a closer hospital too and started to get better. September was also the start of conference madness that lastest to November, with a trip to Dublin for DrupalCon.

Dad & meA group of amazing people

October

October was the month of conferences when I spoke at PHPNW in Manchester, attended OSCON Europe and spoke at the Software Architecture conference, both in London! The other welcome news this month was that Dad came out of hospital.

Coffee breakAttendies to my talk!

November

November is Fireworks Night in the UK which we celebrated with friends. This year, we contributed wood for the bonfire as we've been tiding our garden. I also spoke at Velocity in Amsterdam as did my friend Kevin.

Bonfire nightKevin discussing how to survive the Grand National

December

As usual, the final month of the year found me in a pub with some of my oldest Internet friend from our MMORPG gaming group that I've been part of since 1999. I visited Northern Ireland for the first time. Family from America also visited; I haven't seen my cousin Leigh in 28 years and so had not met her husband or children, so this was very much a highlight.

BL Cronxmas meetupFamilies



All in all a good year, though I will try and space out my conferences a little better in 2017!

On respect in the workplace

I recently came across Don’t be that dude: Handy tips for the male academic, an article covering 20 actions that the author identified as things that men do everyday to perpetuate inequality. A number seem specific to the academic world, but the majority are relevant everywhere.

Now, 20 items is a lot to remember, so I want to call out a few that I see regularly when I'm in offices and at conferences. They are all about respect for the individual and while they aren't necessarily gender specific, I personally have seen many more men doing these things to women than vice-versa and cringe every time I notice.

Don't talk about someone's appearance

Don’t comment on a woman’s appearance in a professional context. It doesn’t matter what your intentions are; it’s irrelevant. Similarly, don’t tell someone they don’t look like a scientist/professor/academic, that they look too young, or they should smile.

Complimenting someone on they way that they look rather than what they have achieved or do is demeaning and disrespectful. Nobody tells me that they like the way that I've ironed my shirt, but I've been in meetings with potential clients where a man has introduced his colleague to me by saying that she must have dressed up today because of the meeting. He didn't comment on the dress sense of any of his male colleagues when introducing them and left me feeling uncomfortable. I have no idea how the woman felt; different and unwelcome I expect.

Be aware of what you say about people, especially women. If you find that you do seem to mention your colleague's clothing or (lack of) makeup, then train yourself to stop talking about it. If you feel like you must make small talk, then find a different topic: something in the news, the travel situation, anything else!

Don't interrupt

Don’t talk over your female colleagues. There is a lot of social conditioning that goes into how men and women communicate differently. You may not realize that you’re doing it, but if you find yourself interrupting women, or speaking over them, stop.

The general case here is don't interrupt. However, it's much more common to see a man who listens intently when his male colleagues are talking, but interrupts and talks over a woman in the meeting. I think this happens because the man doesn't even hear the woman. This is especially frustrating for me as when if you're paying for my time at a meeting, then everyone's input is important.

Pay attention to your own behaviour in meetings. In particular, check that someone else isn't talking the you want to make your point. If you notice that you are interrupting someone else talking, then start consciously waiting for a pause before talking. Your point won't be less important because you waited a few minutes before speaking.

Make tea for and minute your own meetings

Volunteer when someone asks for a note-taker, coffee-run gopher, or lunch order-taker at your next meeting. Don’t let this task fall to women, even if they tend to volunteer (we’re socially conditioned to do so). Make sure that women aren’t being asked to do this more than men.

I see this all the time in client meetings where there is a mix of gender in the room and I now get a bit embarrassed as I used to be that man.

At a previous job, I didn't initially even realise that I was letting a woman team member do much more than her fair share of the tea making rounds. Once I did realise, I told myself that as the senior lead, it was a better use of resources to let the junior members do tea making. That was rubbish. At some point I was educated on this phenomenon and worked on changing the culture by explicitly asking different team members to make the tea.

I have one client where the rule is that the host of the meeting is the note taker and lunch handler which works really well too as it's clear that if you want this meeting to take place, then you get to do some of the leg work. I don't know why they introduced this system: I suspect that it was to promote fewer meetings, but the end result is fairer too.

To sum up

You should read the full list of 20 points as all are worthy of consideration and behaviour change. I've called out the three that I've had to personally work on and improve at and are the ones that I most want to see change on.

In this day and age, be a professional; show some respect.

10 years since my ZF Tutorial

Incredibly, it's been 10 years since I announced my Zend Framework 1 tutorial!

The first code release of Zend Framework (0.1.1) was in March 2006 and I wrote my tutorial against 0.1.5. Just under a year later, in July 2006, version 1.0 was released and I updated my tutorial throughout all the releases up to 1.12. ZF1 had a good run, but all good things come to an end and the official end of life for ZF1 is 28th September 2016. I'm proud that the ZF1 community has been able to maintain v1 for so long after ZF2 was released.

Zend Framework 2.0 was released in September 2012 and I was delighted that my tutorial formed the basis for the Quick Start guide in the official documentation. It has been significantly revised and extended from my initial work by many other people. In July 2016, Zend Framework 3 was released and there's still a Getting Started with Zend Framework tutorial; you can still see the similarities with the very first one!

If you're getting started with Zend Framework today, I hope that you find the Getting Started guide a great introduction to the framework.

Zend Framework has grown incredibly since that first release and with the continuing work on ZF3 and Expressive, it has a long life ahead of it.

Team culture and diversity

Last Friday, I attended a course on managing people led by Meri Williams and learnt a lot. I highly recommend booking her next course if you can. During the Q&A session, there was a question about hiring for diversity and Meri had some very interesting thoughts. I won't try to reproduce them all here as I'll be doing her a disservice.

One comment that resonated was that ideally you want your team members to be able to see others like themselves in the organisation so they can see the potential for their future success and growth within the company.

She also pointed out that you need to ensure that your culture isn't exclusionary before the first hire that changes it. For example, let's say that the entire team always goes out for beers on Friday after work. As soon as you hire a father of young kids, he probably wants to go home on Friday at 5pm so that he can see them before they go to sleep. If you haven't already changed this aspect of your team's culture, then the new team member is blamed for Friday night beers no longer being the same. So not only is he the first family-man in the company, he's now responsible for "ruining" a tradition. Who would want to be that person? How long is he likely to stick around?

The same basic issue applies to everyone who doesn't fit the culture, whether they are a woman, black, over 35, deeply religious, transgender, etc.

Interestingly, this issue also came up in an article published the same day in The Guardian regarding GitHub usernames where Lorna Mitchell commented: "I want people to realise that the minorities do exist. And for the minorities themselves: to be able to see that they aren’t the only ones … it can certainly feel that way some days."

It's really important that you have someone "ahead" of you that you can see is a success. If you don't, then you're more likely to leave, both the company and the industry.

You can see this effect with user groups too. For example, I have children and have to plan around my family commitments when I go out to a meet up in the evening. If a user group announces the next meeting on Twitter or to the mailing list only a few days before it happens, then the odds are that I won't be able to go and the only people that do attend are those that don't have to plan their lives in advance. I know that the user group is not intentionally excluding me; it's the side-effect of their culture.

Obviously, you can't magic up a diverse set of senior developers overnight. However, you can address culture and behaviour in your company or user group that is exclusionary to anyone in a different demographic to your current team.

2015 in pictures

It's that time of year again where I look back at what happened over the past 12 months. Obviously this is mostly an excuse for me to look at the photos I've taken over the year and share some of them as I've done previously.

I attended a lot of conferences this year, though one thing that was different this year was that I attended more than I spoke at. I also spoke at a lot of user groups which was lots of fun.

January

At the very end of January I went to FOSDEM and for the first time ever, I was accompanied by my wife who is currently studying for a degree in computing.

Sebastian talking about the state of PHPUnitJeremy & Sara with the PostgreSQL elephant

February

I spoke at the PHPUK conference in February and have some good memories from this event.

The PHPWomen standRowan & Gary

March

I stepping into the unknown in March and attended a WordCamp! It was a good experience and I got a new scarf!

Q&A with the core developersWapuu Scarf!

April

In April, my friend Alex visited from the Antipodes so I went up to Leeds to meet up with her and other friends. I discovered Fluxx the board game last year when at OSCON, and this was the time that I first played Fluxx the card game. I also visited Glasgow to speak at the PHP user group which was a bit of trek, so I took a couple of days off and photographed railways in the North of England while I was up that way.

Alex is introduced to FluxxPlacing the lamps on 76079

May

May is the month of birthdays in our household. We visited the Happy Potter studios in Leavesden to celebrate! I also visited Belgrade, Serbia to speak at SOLIDday.

The Knight BusThe organisers

June

Seeing friends was the highlights of June.

BeerVisiting friends

July

July was the inaugural PHP South Coast conference and the first time that 19FT has sponsored a conference. Very well organised first event and I'm looking forward to the 2016 edition.

Hallway trackThe organisers

August

August is all about holiday! While in Spain this year, I tried to take a good sunrise picture.

Fishing at sunriseSunrise

September

In one trip, I spoke at PHP Hampshire in Portsmouth and then attended the Lead Developer conference in London. Lead Developer was different type of conference and I'm going to be attending again this year.

HMS WarriorMeri Williams

October

October was the month of two fantastic conferences when I spoke at PHPNW in Manchester and attended OSCON Europe in Amsterdam! The hackathon at PHPNW particularly notable for joind.in as we received many pull requests! I also met my cousin's new twin daughters which was another highlight of a very enjoyable month.

HackathonThe twins with Adam, Oliver & Dave

November

November is Fireworks Night in the UK which we celebrated with friends. I also went to Washington for the php[world] conference. It's always good see boundaries between different PHP communities being broken down.

Watching the bonfireAnthony presents the closing keynote

December

The final month of the year found me in a pub with some of my oldest Internet friends: We've been playing MMOPRGs since 1999 and are suitably irreverent around each other! I also spoke at the first meeting of the PHPMiNDS user group in Nottingham and we released Slim Framework 3!

Palace won!New Slim T-shirt courtesy of @codeguy!




Looking back, I have had a really good 2015 and have some very fond memories; Let's see what 2016 brings!

On blocking ads

There's been a discussion on Twitter this evening about ad-blockers now that Apple has enabled users of iOS to install ad-blocking plugins into their Safari browser. Note that this is not at the OS level and there is no default ad-blocker. The user has to choose to go to the App Store, install an ad-blocker app and then go to Settings->Safari and enable the app.

As we all know, Twitter isn't ideal for conversations requiring even a little bit of nuance, so I'm writing my thoughts here on my blog where I have more room!

Personally, I draw parallels with the older printed medium of a magazine. A magazine has adverts printed on the same physical piece of paper as the article and also comes with lots of separate ads that are inserted into the magazine. I think that reader of the magazine is free to remove the paper inserts without looking at them, put them in the bin and then read the magazine.

Translating to the web, I think that an ad that's served as part of the HTML from the web server is conceptually similar to being printed on the same piece of paper as the advert. Similarly, any ad that is served from a different server and inserted via JavaScript can be considered to be like an insert and may be removed without reading. This argument holds for me as the ad is distinct from the HTML content to such an extent that DNS may not even resolve to the other server or the user's web browser may not support JS (e.g. lynx) and the original article is still provided to the user. As such, an ad-blocker is conceptually the same as a personal assistant that removes the inserts before putting the magazine on the boss' desk. However, with computers, we can all afford a PA if we want one.

Hence, if you're an content producer and want to serve ads on the web, then serve them as HTML with your article and do not use JavaScript. If you do this, then your add will be visible to your readers as content blockers won't catch it.

In this particular case, I see it as no different from the Pop-ups section in Chrome:

Chrome pop-ups

Like ads served from a different domain, I see popups as "inserts", so I'm happy to have the browser not show them. Other people feel that disabling pop-ups interferes with the publisher's right to monetise and so allow all sites to show pop-ups.

It's all about where you draw the line.

Thanks @CalEvans, @codeguy, @Oramius & @JT_Grimes for the civilised discussion. Please feel free to continue the discussion via Twitter or write an article your own blog and ping back!

20 years of PHP

Today marks 20 years since PHP was released by Rasmus Lerdorf and Ben has been asking for how we started our PHP journey.

My first use of PHP was to write a website for an online computer gaming guild for EverQuest, back in 1999. A friend recommended it when I asked him how people programmed webpages in something other the C! That first website is still going and I'm not proud of the code. I'm very proud that it's still going strong and running on PHP 5.6 and has had some very minor updates for PHP version changes:

Oh yeah – I also fixed the SQL inject and XSS vulnerabilities!

That's quite a short list to make a PHP 3 application run on PHP 5.6! Of course, it's not object oriented, so I bypassed the upgrade pain there and it doesn't follow the latest best practices.

That PHP website also led to my first job in the web industry as I was headhunted from my job programming Windows applications. My first commercial website was an internal business application for sales tracking in an Internet hosting company. I've mostly staying in internal business applications and B2B apps ever since!

Of course, the way I write in PHP has changed considerably over the years. My first application was HTML pages with PHP where I needed it. I developed a library of procedural functions and moved most of my PHP code into .inc files. My first framework was Fusebox 4, which I first used in 2005. It was a procedural framework, but was a genuine Front Controller and encouraged separation of concerns. When I was ready to replace it with an OOP framework, Zend Framework had been announced and I jumped onto it…

PHP was built from day one for the web and, for me, it's still the best tool for the job!

Role models

Wikipedia defines a role model like this:

A role model is a person whose behavior, example, or success is or can be emulated by others

All my life, I have identified people that I perceive to be a little better than I am in some facet of life that I want to get better at and I emulate them. I've been doing this all my life. They have been my role models.

My first recollection of this was when I was around 9 or 10 – my last two years of primary school – when I discovered that by emulating and learning how my friend Claire approached maths problems, I got better at it. Similarly at secondary school, I found the academically best people I could to inspire me.

At University there were three people that had characteristics that I wanted in myself. This was when I discovered that a role model could inspire me to change how I view and live my life as well as improve my abilities. My role models helped me get a first class degree, but one of them unknowingly helped me become a more empathetic person.

This trend that has continued all the way through my life. I've found people who are better than me and have emulated them. I pay attention to how they behave & what they do and try to change appropriately. My role models have (and continue to) inspired me to be better.

I cannot thank them enough.

I hadn't thought about the gender mix of my inspirations before reading Zaron Burnett's Can A Man Have Female Role Models? I found this article eye-opening and I highly recommend that you take the time to read. He points out that the way our society portrays and treats women has done us all (yet another) disservice by hindering our ability to select the best role-models we can:

This hidden hierarchy of gender in language and culture runs rampant as blackberry thicket and is just as thorny and difficult to remove. It’s that bias that makes men reluctant to be like women, or identify with women, or imagine life from a woman’s eyes, or conceive of what a day in her experience might be like that. That’s a problem.

A smart man selects from both men and women for his role models. He learns from both and draws lessons from the whole body of humanity’s experience, rather than only taking counsel from the half he might meet in a public restroom.

I will look up to whomever I choose in order to better myself. I suggest you do too.

Ally

One thing I've noticed as I try to learn how to become more aware of the diversity issues in my world is that it's really hard for someone to "get it" if they don't "live it". I think this occurs at all levels.

For my position in society, I don't get how it feels to be a black man with the constant assumption that "I'm up to no good". Similarly, I lack that fundamental understanding for other groups of people with fewer advantages than I have.

Walking-the-walk is the only way to become intimately immersed in something and fully understand it. I love listening to music and I know a lot about how it is created, but I'm not a musician.

This is why those who support people who are subject to discrimination and prejudice are called allies. I like this term as it fundamentally understands the difference between someone who lives the situation daily and someone who wants the world to change so that she doesn't have to.

I call myself a feminist and think that I'm an ally. Becoming an ally is a journey. It starts with noticing the discrimination. Common steps along the path are to learn about it, and then change your behaviour. Over time I've learnt to listen to what women tell me without trying to justify to myself or tell them about why they are misunderstanding. I've learnt to shut-up. I've been trying to change my language to be less patronising; I don't joke about the kitchen. At a conference, I start with the assumption that every woman I meet there is a developer and I don't ask if they have children because I assume that we can talk about dev subjects.

I make mistakes often.

Changing habits is hard and this is a journey. I'm moving in the right direction; I would like you to come along with me.