PHP code example of jbc / php-cron
1. Go to this page and download the library: Download jbc/php-cron 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/ */
jbc / php-cron example snippets
use Jbc\PhpCron\Scheduler;
$scheduler = new Scheduler(
timezone: new \DateTimeZone('America/Sao_Paulo'),
);
$scheduler->schedule('* * * * *', function () {
echo 'Runs every minute' . PHP_EOL;
});
$scheduler->schedule('0 9 * * *', function () {
echo 'Runs every day at 9am' . PHP_EOL;
});
$scheduler->run();
$scheduler
->schedule('* * * * *', fn() => myFunction())
->name('my-job')
->withoutOverlapping()
->onlyIf(fn() => true)
->onError(fn(\Throwable $e) => logger($e));
bash
composer bash
php bin/cron