We have a couple of new features coming in to PHP 5.6 with names that sound much less exciting than the features they actually represent: "variadic functions" sound positively academic, and "argument unpacking" isn't exactly catchy. However they both use a new operator in PHP which looks like an elipsis (three dots ...) and is referred to as either the splat operator or the scatter operator. I included them in a recent version of my "Upgrading PHP" talk so I thought I'd share the examples here too in case anyone is interested. Continue reading
Recent additions to the joind.in API have introduced some new dependencies so we decided we'd start using Composer to manage these - but we don't want to run composer unsupervised. I'm sure this will bring the rain of "just run
composer install, it's probably mostly almost safe" criticism, but actually it's quite tricky to run Composer without excluding
vendor/ from source control so I thought I'd share how we did it so that anyone who wants to do so can learn from my experience!
I have just introduced Beanstalkd into my current PHP project; it was super-easy so I thought I'd share some examples and my thoughts on how a job queue fits in with a PHP web application.
I have an API backend and a web frontend on this project (there may be apps later. It's a startup, there could be anything later). Both front and back ends are PHP Slim Framework applications, and there's a sort of JSON-RPC going on in between the two.
The job queue will handle a few things we don't want to do in real time on the application, such as:
- updating counts of things like comments; when a comment is made, a job gets created and we can return to the user. At some point the job will get processed updating the counts of how many comments are on that thing, how many comments the user made, adding to a news feed of activities ... you get the idea. Continue reading
I get a lot of complaints about an API that I maintain (http://api.joind.in) which is "missing" the ID field. This ID field is the database's primary key; if the user doesn't have access to the database (they don't), then it seems to me that the primary key probably isn't all that useful.
Instead, the API publishes each record with a unique
uri field. If this record is referred to by another record, then this full identifier will be used in every case. If this record should be included in a collection, this exact same identifier will be used there, too. You can reach the resource directly by requesting its URI. In the same way that we might refer to a website by its URL, we refer to records in RESTful systems by their URI*. If you need to store these somewhere for your own use, you can use whatever key you like with the local storage, you may even choose to use the
uri field as it is unique.
* URI stands for Unique Resource Identifier
I had a good experience implementing beanstalkd for the first time last week, so I thought I'd write down how that went and what I learned.
My requirements were simply to add both asynchronous (for processing things like recalculating counts) and periodic (mostly for garbage collection) tasks to a PHP application. The application has a separate web application and backend API, both made of PHP's Slim framework, and the API talks to MySQL. It's all very lightweight and scalable, and I was looking for something to fit in with what we have, with good PHP support.
Enter beanstalkd, it's a super-simple job queue and has great PHP support in the shape of Pheanstalk (I'm saving my PHP + beanstalkd examples for another day because this post would get too long to read otherwise!). I've used gearman in the past but beanstalkd seemed lighter, and when I started looking at their documentation I discovered that I had a working installation in about the time it would take me to fall off a log - which is always a good indicator of a tool that will be fun to work with :) Continue reading
I've had a little flurry of enquiries about training lately, so I thought I'd mention the courses I have coming up, as especially the PHP ones are topics that I don't run public classes on all that often. At the time of writing I have some space on all of these classes: Continue reading
My current project sees Celery (a python distributed task queue) added to my PHP application. There's a handy PHP interface to the RabbitMQ that Celery uses as a backend, which makes it easy for me to create jobs, called celery-php. This requires either the PECL AMQP extension or alternatively it has experimental support for the PHP library for AMQP - I would normally prefer the PECL version but ran into version compatibility problems, missing manual pages, and decided that a pure PHP solution might be more portable and perhaps I would just add the experimental branch to my
composer.json file for this project. Continue reading
I can't be the only person who always seems to be switching between multiple development branches. Sometimes I get distracted for a few days (I'm also part time, which doesn't help!) and then I can't even remember what I was doing or what the branch was called.
The remedy for this situation? The
--all switch to
git log. Continue reading
I have a thinkpad laptop with a touchscreen and a swivel so it can fold up and pretend to be an oversized tablet. I like it a lot, but the touch screen interface hasn't been all that useful since I normally use this machine docked and then it maps the whole of one screen as a touch interface across my multiple monitors as a desktop space!
I recently sorted this out, so I thought I'd share the scripts that worked for me on Saucy Salamander Ubuntu 13.10 with Unity.
First, work out which device you actually want:
$ xsetwacom --list
Wacom Bamboo stylus id: 11 type: STYLUS
Wacom ISDv4 E6 Pen stylus id: 13 type: STYLUS
Wacom ISDv4 E6 Finger touch id: 14 type: TOUCH
Wacom Bamboo eraser id: 19 type: ERASER
Wacom Bamboo cursor id: 20 type: CURSOR
Wacom Bamboo pad id: 21 type: PAD
Wacom ISDv4 E6 Pen eraser id: 22 type: ERASER
xsetwacom to get the right touch input relating to the correct screen, even with multiple monitors:
$ xsetwacom set "Wacom ISDv4 E6 Finger touch" MapToOutput LVDS1
At this point I should point out that my touch screen is incorrectly configured and therefore needs the script above running every time I plug or unplug an external display. Since I dock my machine, move it almost daily, and regularly present ... that's kinda irritating. Any solutions on improving that are welcome.
My current project does periodic releases, we build a few things, then we work on getting a bunch of user feedback and changing/fixing things before we actually release. This means we need to be organised with tags and branches. We're using GitHub for collaboration, including our issue trackers, commits which contribute to an issue have the issue number in the commit message, and when a branch merges in to the main line, we use the "fixes #42" notation to simultaneously close off the issue that it relates to.
This has been working pretty well, and today I got the question "what's new since I last saw this project?" - so I created a changelog. It's rather rough-and-ready but I had fun so I thought I'd share. Continue reading