1. Go to this page and download the library: Download hellogerard/jobby 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/ */
hellogerard / jobby example snippets
// Ensure you have included composer's autoloader
();
// Every job has a name
$jobby->add('CommandExample', [
// Run a shell command
'command' => 'ls',
// Ordinary crontab schedule format is supported.
// This schedule runs every hour.
'schedule' => '0 * * * *',
]);
$jobby->run();
/* ... */
$jobby->add('LoggingExample', [
'command' => 'ls',
'schedule' => '0 * * * *',
// Stdout and stderr is sent to the specified file
'output' => 'logs/command.log',
]);
/* ... */
/* ... */
$jobby->add('DisabledExample', [
'command' => 'ls',
'schedule' => '0 * * * *',
// You can turn off a job by setting 'enabled' to false
'enabled' => false,
]);
/* ... */
/* ... */
$jobby->add('ClosureCommandExample', [
// Use the 'closure' key
// instead of 'command'
'closure' => function() {
echo "I'm a function!\n";
return true;
},
'schedule' => '0 * * * *',
]);
/* ... */
/* ... */
$jobby->add('DateTimeExample', [
'command' => 'ls',
// Use a DateTime string in
// the format Y-m-d H:i:s
'schedule' => '2017-05-03 17:15:00',
]);
/* ... */
/* ... */
$jobby->add('Example', [
'command' => 'ls',
// Use any callable that returns
// a boolean stating whether
// to run the job or not
'schedule' => function(DateTimeImmutable $now) {
// Run on even minutes
return $now->format('i') % 2 === 0;
},
]);
/* ... */