fm-labs / cakephp-cron
Cron Job plugin for CakePHP
Installs: 70
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=8.0
- cakephp/cakephp: ^4.0
Requires (Dev)
README
A Cronjob plugin for CakePHP
Installation
composer require fm-labs/cakephp-cron
Create a custom CronTask
namespace App\Cron class MyCronTask implements \Cron\Cron\ICronTask { public execute() { // ... do some magic ... //return new CronTaskResult(false, "Something went wrong") return new CronTaskResult(true, "Success") } }
Configuration
In your Plugin.php
or bootstrap.php
\Cron\Cron::setConfig('my_cron', [ 'className' => \App\Cron\MyCronTask, 'interval' => 3600, // interval in seconds ])
Execute cron tasks
Via Http / Browser
# to run a specific task curl -v https://YOUR_BASE_URL/cron/my_cron # to run all tasks curl -v https://YOUR_BASE_URL/cron/all
Via CLI
# to run a specific task ./cake cron run my_cron # to run all tasks ./cake cron run all
Password protect cron task execution
# to run all tasks
curl -v https://USER:PASSWORD@YOUR_BASE_URL/cron/all
Under the hood
- Tasks are statically configured via
Cron
class. - The
CronController
instantiates theCronManager
- The
CronManager
loads configured tasks fromCron
class and on invokation:- Instantiates the cron task class (implementing the
ICronTask
interface) - Fires the
Cron.beforeTask
event - Executes the cron task
- Fires the
Cron.afterTask
event
- Instantiates the cron task class (implementing the