Skip to content

Signaling PHP in action

Dear Reader,

No, this is not me announcing a followup book. :) This is just a quickie to point out that Matthias Noback wrote a blog post a little bit ago titled “Symfony2: Add a global option to console commands and generate a PID file”. In it he discusses Appendix A of “Signaling PHP” that talks about creating PID files.

Here’s the obligatory quote:

In Appendix A of “Signaling PHP”, Cal writes about a way to extend a Symfony command to automatically create such a PID file before executing its task, and to delete this file afterwards. In the example code in the appendix the command gets to choose the filename of the PID file. However, since a PID file is only useful for external applications that handle starting and terminating the command, you may want to let the location and name of the PID file be determined by the external application itself. In other words, you’d want to be able to run a command and use an option to determine the location of the PID file:

app/console my:command --pidfile=/home/matthias/

I’d like every command in my application to have this extra option. Unfortunately there is no standard way to do this with Symfony. So the first thing we need to do is find a way to globally add an option to the Symfony console application. Let me give away the clue: I did some research and found a way to do this. It is a bit of a hack, but not too bad a hack, since I don’t think it will break anywhere in the near feature.

The blog post goes on to shows a better way to handle the naming and location of the PID files, as well as how to make it a seamless part of all your commands.

If you work with symfony from the command line, this blog post is an excellent read and full of cool code. Check it out.

Thanks Matthias! :)

Until next time,
I <3 |<