Last updated at Wed, 25 Oct 2017 19:33:16 GMT

I went along to the inaugural PHP meetup in Engineyard last Tuesday in the hope of PHP enlightenment. PHP wouldn’t be my goto language for most things but it does seem to have a very large following and a vibrant community and I was sure I would get something out of these talks.

Realtime communication using PHP, Redis and socket.io

The first talk of the night was by David Clay Smith about doing real time communication for PHP applications. The typical use cases were touted; instant messaging, gaming and stock tickers. A short history on the evolution of real time communication on the web gave us an insight into how this sort of problem would have been tackled in the past.

Of course the html5 way to do real time communication is to use WebSockets. Being a PHP novice my initial thought was that there must be a PHP library for WebSockets. There are actually a few with  Ratchet and Wrench being mentioned in the presentation. However, as this Stack Overflow post mentions, “PHP is not designed for long running bidirectional communication and will cause an entire Apache process/thread to lock up with each new connection.”.

As it turns out there’s a better way to use WebSockets in your PHP application; use node.js and socket.io. Socket.io is a great javascript library for realtime communication. It will attempt to communicate using WebSockets but falls back to other methods such as ajax long polling or the forever iFrame depending on the environment. This flexibility allows you to use socket.io on most browsers(IE 5.5+ is supported!). The presentation then went on to explain how you can use PHP and socket.io in your application and get them to communicate easily. You can use PHP for what you’d normally use PHP and use node.js for the real time communication part of the application.

One of the more interesting parts of the presentation was how Redis was used for communication between the PHP code and the node.js code. The idea was that node.js code would subscribe to a channel using Redis’ pub/sub functionality and the PHP code would publish to this channel. There are a lot of client libraries for Redis , including for PHP and node.js, and using these you should be able to easily add some code that can publish or subscribe to a Redis channel.

The entire flow looks like this:

Web Client 1 -> PHP app -> Redis -> Node.js (Broadcast) -> Web Client 2..n

It was nice to see an application leverage the strengths of different languages to accomplish its goal. We have a similar philosophy in Logentries. We use Django for our web server and have a java server for processing the log data. We also use a C++ library for regex handling on the server side.

Moving away from wordpress with limited resources

The second talk of the evening was by John Needham from thejournal.ie. He described how they tried to get away from the quagmire of WordPress development. The aim was to avoid using WordPress for the front end of their site and for their mobile apps. They still wanted to use it to allow the journalists to add in the content.

The solution was to put an API in front of the WordPress database and code all their frontend applications against this api.

One of the comments that John made in the talk was about how they add in new features – “Ship it and iterate”. By focusing on the bare functionality to get a shippable feature they could release a feature early. If an improvement is needed then that can be added in the next iteration. I really like this approach as it allows developers to focus on the most important part of the code.

Version control your infrastructure

The third talk by Ross Duggan highlighted the importance of storing the configuration for your infrastructure in version control. He made some good points about being able to recover quickly if there are some issues with the infrastructure.

Overall the talks were informative and enjoyable. Even though the talks focussed on PHP many of the ideas could be used with other languages and platforms.