PHP code example of joesweeny / schedule

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

    

joesweeny / schedule example snippets


use JoeSweeny\Schedule\Task;

$task1 = new Task('delete:files');

$task2 = new Task('notify:users', ['--admin']);

use JoeSweeny\Schedule\Task;

$task1 = new Task('delete:files');

// Task will run every Monday at 00:00
$task1->weekly();

// Additional frequency methods can be chained to the Task to be more specific

$task2 = new Task('notify:users', ['--admin']);

// Task will run every Wednesday at 09:00AM
$task2->wednesdays()->at('09:00');

// Note any Task without a frequency specified will automatically run every minute of every day

use JoeSweeny\Schedule\Task;
use JoeSweeny\Schedule\Schedule;

$task1 = (new Task('delete:files'))->sundays();

$task2 = new Task('notify:users', ['--admin']);

$schedule = new Schedule;

$schedule->addTask($task1)->addTask($task2);

$schedule->getTasks() 
// Will return [(new Task('delete:files'))->sundays(), new Task('notify:users', ['--admin'])] 

use JoeSweeny\Schedule\Task;
use JoeSweeny\Schedule\Schedule;

$task1 = (new Task('delete:files'))->sundays();

$task2 = new Task('notify:users', ['--admin']);

$schedule = new Schedule;

$schedule->addTask($task1)->addTask($task2);

$schedule->getDueTasks();
// Will return an array of Task objects ready to be executed

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use JoeSweeny\Schedule\Task;
use JoeSweeny\Schedule\Schedule;

$schedule = new Schedule;

$application = new Application('CLI Application');

$schedule
    ->addTask((new Task('delete:files'))->sundays())
    ->addTask(new Task('notify:users', ['--admin']));

$due = $schedule->getDueTasks();

foreach($due as $task) {
    $application->run(new StringInput($task->execute()), $output = new BufferedOutput);
}