view raw
史京迪 史京迪 - 8 months ago 94
PHP Question

Cron Job in symfony2

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?


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.