PHP code example of visavi / crontask

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

    

visavi / crontask example snippets




class HelloDailyTask extends \Crontask\Tasks\Task
{
    public function run()
    {
        $this->setOutput('Hello World');
    }
}

class ShellMondayTask extends \Crontask\Tasks\Shell
{
    protected $command = "echo Hello Monday";
}

$taskList = new \Crontask\TaskList();

// Add task to run at 12:00 every day
$taskList->addTask((new HelloDailyTask)->setExpression('12 0 * * *'));

// Add task to run every hour
$taskList->addTask((new HelloDailyTask)->setExpression('@hourly'));

// Add task to run at 12:00 every Monday
$taskList->addTask((new ShellMondayTask)->setExpression('12 0 * * 1'));

// or
$taskList->addTasks([
    (new HelloDailyTask)->setExpression('12 0 * * 1'),
    (new HelloDailyTask)->setExpression('@hourly'),
    (new ShellMondayTask)->setExpression('12 0 * * 1'),
]);

$taskList->run();

* * * * * php /path/cron.php