PHP code example of elstc / cakephp-cron-jobs

1. Go to this page and download the library: Download elstc/cakephp-cron-jobs 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/ */

    

elstc / cakephp-cron-jobs example snippets


use Cake\Event\Event;
use Cake\Event\EventManager;

EventManager::instance()->on('CronJobs.buildSchedule', static function (Event $event) {
    /** @type \Elastic\CronJobs\Schedule\CakeSchedule $schedule */
    $schedule = $event->getSubject();
    
    // Add scheduled command
    $schedule->run('touch tmp/crunz-time-from-event')
        ->description('your job description')
        ->everyDay()
        ->at('09:00');

    // Add scheduled cake's command
    // such as `bin/cake your_command comannd_arg1 --command-option --some-opt=value`
    $schedule->runCommand('your_command', [
            'comannd_arg1',
            '--command-option',
            '--some-opt' => 'value',
        ])
        ->description('your job description')
        ->cron('0 3 * * *');
});

$this->addPlugin('Elastic/CronJobs');