1. Go to this page and download the library: Download eurotolia/mastercron 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/ */
eurotolia / mastercron example snippets
// tasks/backupTasks.php
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run('cp project project-bk');
$task->daily();
return $schedule;
// tasks/FirstTasks.php
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run('cp project project-bk');
$task
->daily()
->description('Create a backup of the project directory.');
// ...
// IMPORTANT: You must return the schedule object
return $schedule;
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run(PHP_BINARY . ' backup.php', ['--destination' => 'path/to/destination']);
$task
->everyMinute()
->description('Copying the project directory');
return $schedule;
use Crunz\Schedule;
$schedule = new Schedule();
$x = 12;
$task = $schedule->run(function() use ($x) {
// Do some cool stuff in here
});
$task
->everyMinute()
->description('Copying the project directory');
return $schedule;
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run('command/to/run');
$task->everyFiveMinutes();
$schedule
->onError(function() {
// Send mail
})
->onError(function() {
// Do something else
});
return $schedule;
namespace Vendor\Package;
use Crunz\Application\Service\ConfigurationInterface;
use Crunz\Application\Service\LoggerFactoryInterface;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
final class MyEchoLoggerFactory implements LoggerFactoryInterface
{
public function create(ConfigurationInterface $configuration): LoggerInterface
{
return new class extends AbstractLogger {
/** @inheritDoc */
public function log(
$level,
$message,
array $context = array()
) {
echo "crunz.{$level}: {$message}";
}
};
}
}
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run(PHP_BINARY . ' email.php');
$task
->everyFiveMinutes()
->before(function() {
// Do something before the task runs
})
->before(function() {
// Do something else
})
->after(function() {
// After the task is run
});
$schedule
->before(function () {
// Do something before all events
})
->after(function () {
// Do something after all events are finished
})
->before(function () {
// Do something before all events
});
bash
mkdir tasks && cd tasks
nano GeneralTasks.php