Managing Console scripts with Silex

I’ve wrote about using the ConsoleServiceProvider with Silex a few months ago and after a few hours of programming, I had a lot of scripts which needed to run continuously. When debugging I needed to kill and restart those fairly quick. I’ve created a console script with a few helper classes to make my set up more manageable. I’ve added all these files to my silex-base repo. you can find everything in the readme.md file on how to use this.

When you want to create a script it works like this: First you create your own script in app/console. Make sure this file has all the right permissions. The next step is to add this to the config in the Console.php file. You can add a description, name & an interval. The default is an interval of 60 seconds. Next step is to create your own Command file. This file has to implement two methods: Configure (where you will fetch the config from the Console class) and execute (where you will execute your own code – see using the ConsoleServiceProvider with Silex a few months ago). I’ve also added a Timing class which calculates how long a script runs.

Console Scripts Config

When this is all configured, running the “app/console/console scripts” command will try to execute all scripts that are available.
You can kill those scripts with the –kill optional argument. You can start (or kill) a single script like this:

app/console/console scripts import (--kill)

The output of all those scripts can be found in the app/logs/console files.

Example

Advertisement

Leave a Reply brah!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s