Cron Job in symfony2

后端 未结 4 2031
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-01 06:52

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 con

4条回答
  •  生来不讨喜
    2021-02-01 07:43

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

    crontab -e -u 
    

    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.

提交回复
热议问题