PHP code example of azurre / php-cron-scheduler

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

    

azurre / php-cron-scheduler example snippets


$loader = re\Component\Cron\Scheduler;
use Azurre\Component\Cron\Expression;

$e = new Expression();

echo $e->monthly(28); // 0 0 28 * *
echo $e->weekly($e::FRIDAY)->at('05:30'); // 30 5 * * 5
echo $e->daily('06:10'); // 10 6 * * *

echo Expression::create()  // */5 0 16 1 5
    ->setMinute('*/5')
    ->setHour('*')
    ->setDayOfMonth(16)
    ->setDayOfWeek('fri')
    ->setMonth('Jan');

// ------------

$testFunc = function () {
    echo 'TEST OK';
};
$scheduler = new Scheduler();
$scheduler
    ->addJob('* * * * *', function() {
        // just do something
    })->addJob('0 0 * * * *', $testFunc);
$scheduler->run();

// -----------

$logPath = '/path/to/log.log';
$scheduler = new Scheduler('2021-07-05 06:10:00');
$scheduler->addJob($e, function () use($logPath) {
    // run standalone php script
    $cmd = "/usr/bin/php /path/to/script.php >> {$logPath} 2>&1";
    system($cmd);
});
$scheduler->run();

composer 

* * * * * /usr/bin/php /path/to/project/scheduler.php >> /path/to/project/scheduler.log 2>&1