Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron Job in symfony2

Tags:

php

cron

symfony

I create a console command in my project. I want it to be executed everyday at 7 p.m. How could i do it in symfony2? A basic php cron job way or symfony2 have something more convenient? Thanks

like image 559
史京迪 Avatar asked Aug 27 '13 09:08

史京迪


2 Answers

You can use the basic cron. On debian or ubuntu you can do this:

crontab -e -u <username>

Where username is the name of the user that should execute the command. In the editor add your command. Here is a good explanation how the line should look. For a Symfony2 command something like this should work:

* * * * * /usr/bin/php /var/www/symfony2/app/console your:command --option=123

This will execute your:command --option=123 every minute.


On a windows machine you can use the ac command. It is available for windows 7 by default. Read the docs here. It should look something like this:

AT 00:00 /every:M,T,W,Th,F "php /var/www/symfony2/app/console your:command --option=123"

Make sure that php is available globaly or the path to the php.exe file is correct.

like image 142
ferdynator Avatar answered Nov 18 '22 12:11

ferdynator


You can just set a cron in crontab to execute your symfony command,

e.g.

0 19 * * * /var/www/symfony/app/console YOUR_COMMAND

like image 38
vishal Avatar answered Nov 18 '22 14:11

vishal