I'm trying to find out how to set up a cron job in Laravel 4, and the command I would need to run in artisan for it.
In Laravel 3, there were Tasks
but these don't seem to be there anymore and there is no documentation as to how to do it...
I'm trying to find out how to set up a cron job in Laravel 4, and the command I would need to run in artisan for it.
In Laravel 3, there were Tasks
but these don't seem to be there anymore and there is no documentation as to how to do it...
Tasks have been replaced with commands, which are the same thing in Laravel 4, but integrated with Symfony's console component, and even more powerful than before.
Alternative, if you don't like commands there is an unofficial Laravel 4 cron package: https://github.com/liebig/cron
Below I detail a tutorial for using
commands
inLaravel 4
with cron. I have divided into four steps to make it easier to follow.STEP #1: Create a command in Laravel 4:
With command above, Laravel will create a file named
RefreshStats.php
in directoryapp/commands/
RefreshStats.php it's a file like this:
STEP #2: Simple "configuration" of RefreshStats file:
You should change this line:
to something like this:
If you don't need arguments (same for options), change this line:
to:
And now pay attention to the
fire
function. The command will execute source code that is wrote in that function. Example:STEP #3: Register the command:
You need to register the command. So open
app/start/artisan.php
file, and add one line as below:STEP #4: Create CRON scheduled task:
Finally, you can add a scheduled task as follow:
And add a line (run command every 30 minutes) like below:
And all will work automagically!