SbkCronBundle
Symfony2 Bundle for setting up cron jobs via configuration., (*1)
, (*2)
Installation
Prerequisites
This bundle requires Symfony 2.1+, as it must be installed with composer., (*3)
Download SbkCronBundle with composer
Add the following to your project composer.json
:, (*4)
{
"require": {
"sbk/cron-bundle": "dev-master"
}
}
Now install it with this command:, (*5)
$ php composer.phar update sbk/cron-bundle
The bundle should be downloaded to the vendor
directory., (*6)
Enable the bundle
You need to add the bundle in app/AppKernel.php
, (*7)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Sbk\Bundle\CronBundle\SbkCronBundle(),
);
}
Import Services
The CronBundle depends on certain services, so you need to import the service configuration in app/config/config.yml
, (*8)
imports:
# ...
- { resource: @SbkCronBundle/Resources/config/services.yml }
Now you should be able to use the Cron Manager., (*9)
Usage
Configuring Tasks
Tasks can be configured in app/config/config(_prod).yml
., (*10)
sbk_cron:
tasks:
clearcache:
command: "cache:clear --env=prod"
expression: "0 0 * * *"
listoutput:
bin: "ls"
script: ""
command: "-l > /var/log/listoutput.log"
expression: "@daily"
Each entry in sbk_cron.tasks
represents a task., (*11)
command
, (*12)
The command to execute. By default the cron manager will prepend php %kernel.root_dir%/console
before the command name, so configuring console commands is easy. You can run every command you want with this bundle, read on how to do so., (*13)
expression
, (*14)
The cron expression, any valid expression that you would enter in a cron table., (*15)
bin
, (*16)
The binary which will execute the command (php
by default, you could enter ''
to omit the bin in the execution command), (*17)
script
, (*18)
The script that will be called (%kernel.root_dir%/console
by default)., (*19)
Runnign the master cron job
Even if you can configure all cron jobs with this bundle, you need to add one line to the crontab manually, the cron:run
command., (*20)
* * * * * php /var/www/app/console cron:run
This will execute the cron manager every minute., (*21)
The manager will check which tasks need to be executed and will create background processes for every due task., (*22)