PHP code example of flexic / scheduler

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

    

flexic / scheduler example snippets


class MyScheduleEvent implements \Flexic\Scheduler\Interfaces\AbstractScheduleEventInterface
{
    public function __invoke(): void
    {
        // ... do something
    }
    
    public function configure(Flexic\Scheduler\Interfaces\ScheduleInterface $schedule): void
    {
        $schedule->cron('* * * * *');
    }
}

# Options for worker
$options = [];
$events = [
    new MyScheduleEvent(),
];

$worker = new \Flexic\Scheduler\Worker(
    new Flexic\Scheduler\Configuration\WorkerConfiguration($options),
    $events,
    new \Symfony\Component\EventDispatcher\EventDispatcher(),
);

$worker->start();

class MyScheduleEventFactory implements \Flexic\Scheduler\Interfaces\ScheduleEventFactoryInterface
{
    public function create(): array {
        return [
            new MyScheduleEvent('foo'),
            new MyScheduleEvent('bar'),
        ];
    }
}
bash
php bin/schedule ./path/to/event_config.php ./path/to/event_config_1.php