1. Go to this page and download the library: Download hbalkhi/yii2-scheduler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace app\tasks;
/**
* Class AlphabetTask
* @package app\tasks
*/
class AlphabetTask extends \hbalkhi\scheduler\Task
{
public $description = 'Prints the alphabet';
public $schedule = '0 * * * *';
public function run()
{
foreach (range('A', 'Z') as $letter) {
echo $letter;
}
}
}
Event::on(AlphabetTask::className(), AlphabetTask::EVENT_BEFORE_RUN, function ($event) {
Yii::trace($event->task->className . ' is about to run');
});
Event::on(AlphabetTask::className(), AlphabetTask::EVENT_AFTER_RUN, function ($event) {
Yii::trace($event->task->className . ' just ran '.($event->success ? 'successfully' : 'and failed'));
});
$application->on(\hbalkhi\scheduler\events\SchedulerEvent::EVENT_AFTER_RUN, function ($event) {
if (!$event->success) {
foreach($event->exceptions as $exception) {
throw $exception;
}
}
});
bash
php yii migrate up --migrationPath=vendor/hbalkhi/yii2-scheduler/src/migrations
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.