PHP code example of bayfrontmedia / cron-scheduler
1. Go to this page and download the library: Download bayfrontmedia/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/ */
bayfrontmedia / cron-scheduler example snippets
* * * * * path/to/php/bin path/to/cron.php > /dev/null 2>&1
$current_time = new DateTime('2020-09-08 10:55:00');
try {
$result = $cron->run($current_time)
} catch (FilesystemException $e) {
die($e->getMessage());
}
try {
$cron->php('job-name', 'path/to/php/file.php');
} catch (LabelExistsException $e) {
die($e->getMessage());
}
try {
$cron->php('job-name', 'path/to/php/file.php')->always();
} catch (LabelExistsException $e) {
die($e->getMessage());
}
try {
$cron->php('job-name', 'path/to/php/file.php')->when(function($return) {
return $return;
}, [
'return' => true
]);
} catch (LabelExistsException $e) {
die($e->getMessage());
}
try {
// 10:00pm Monday-Friday
$cron->php('job-name', 'path/to/php/file.php')->at('0 22 * * 1-5');
} catch (LabelExistsException $e) {
die($e->getMessage());
}
try {
$cron->php('job-name', 'path/to/php/file.php')->everyHours(2);
} catch (CronException $e) {
die($e->getMessage());
}
try {
$cron->php('job-name', 'path/to/php/file.php')->daily('16:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every January 10th
$cron->php('job-name', 'path/to/php/file.php')->january(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every February 10th
$cron->php('job-name', 'path/to/php/file.php')->february(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every March 10th
$cron->php('job-name', 'path/to/php/file.php')->march(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every April 10th
$cron->php('job-name', 'path/to/php/file.php')->april(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every May 10th
$cron->php('job-name', 'path/to/php/file.php')->may(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every June 10th
$cron->php('job-name', 'path/to/php/file.php')->june(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every July 10th
$cron->php('job-name', 'path/to/php/file.php')->july(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every August 10th
$cron->php('job-name', 'path/to/php/file.php')->august(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every September 10th
$cron->php('job-name', 'path/to/php/file.php')->sepember(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every October 10th
$cron->php('job-name', 'path/to/php/file.php')->october(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every November 10th
$cron->php('job-name', 'path/to/php/file.php')->november(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}
try {
// 11:30pm every December 10th
$cron->php('job-name', 'path/to/php/file.php')->december(10, '23:30');
} catch (CronException $e) {
die($e->getMessage());
}