Sometimes, we will want background processes, periodic tasks, or maintenance tasks to occur. This is where FuelPHP tasks come in handy. They can be run via the command-line tool, or set up as a periodic task on Windows, or cron job on Mac OSX and *nix. They can call upon modules and other classes just like controllers can.
Tasks should be placed in the fuel/app/tasks
folder and, by default, only a run()
method needs to be defined within the class. If you need other methods, these can be added in the usual way for PHP classes.
The tasks are called using the Oil refine
command. FuelPHP comes with an example task called robots
and will be included in the fuel/app/tasks
folder.
To call the main method of the robot task, you can run the following command:
$ php oil refine robot
The run()
method in the robot
task has a variable defined, allowing you to pass a string via the oil refine
command. Typing the following command line will change the message in the task:
$ php oil refine robots "Kill...