PHP code example of eric28 / dispatcher

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

    

eric28 / dispatcher example snippets


use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Drivers\DateTime\Scheduler;

class MyCommand extends ScheduledCommand {

    //your command name, description etc.

	public function schedule(Schedulable $scheduler)
	{
        //every day at 4:17am
        return $scheduler
            ->daily()
            ->hours(4)
            ->minutes(17);
    }

}

        'Indatus\Dispatcher\ServiceProvider',

* * * * * php /path/to/artisan scheduled:run 1>> /dev/null 2>&1

use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Indatus\Dispatcher\Scheduling\Schedulable;
use Indatus\Dispatcher\Drivers\DateTime\Scheduler;

	/**
	 * When a command should run
	 *
	 * @param Scheduler $scheduler
	 *
	 * @return Scheduler
	 */
	public function schedule(Schedulable $scheduler)
	{
		return $scheduler;
    }

    public function user()
    {
        return 'backup';
    }

    public function environment()
    {
        return ['development','staging'];
    }

    public function runInMaintenanceMode()
    {
        return true;
    }

	public function schedule(Schedulable $scheduler)
	{
        return [
            // 5am Mon-Fri
            $scheduler->everyWeekday()->hours(5),

            // 2am every Saturday
            App::make(get_class($scheduler))
                ->daysOfTheWeek(Scheduler::SATURDAY)
                ->hours(2)
        ];
    }


	public function schedule(Schedulable $scheduler)
	{
		return [
            // equivalent to: php /path/to/artisan command:name /path/to/file
            $scheduler->args(['/path/to/file'])
                ->everyWeekday()
                ->hours(5),

            // equivalent to: php /path/to/artisan command:name /path/to/file --force --toDelete="expired" --exclude="admins" --exclude="developers"
            $scheduler->args(['/path/to/file'])
                ->opts([
                    'force',
                    'toDelete' => 'expired',
                    'exclude' => [
                        'admins',
                        'developers'
                    ]
                ])
                ->daysOfTheMonth([1, 15])
                ->hours(2)
        ];
	}

	public function schedule(Schedulable $scheduler)
	{
        //every day at 4:17am
        return $scheduler->daily()->hours(4)->minutes(17);
    }

	public function schedule(Schedulable $scheduler)
	{
        //every Tuesday/Thursday at 5:03am
        return $scheduler->daysOfTheWeek([
                Scheduler::TUESDAY,
                Scheduler::THURSDAY
            ])->hours(5)->minutes(3);
    }

	public function schedule(Schedulable $scheduler)
	{
        //the second and third Tuesday of every month at 12am
        return $scheduler->monthly()->week([2, 3])->daysOfTheWeek(Day::TUESDAY);
    }

    'driver' => '\MyApp\ScheduleDriver'

* * * * * /usr/bin/rcron php /path/to/artisan scheduled:run 1>> /dev/null 2>&1

$ php artisan scheduled:run --debug                                                                                        
Running commands...
     backup:avatars: No schedules were due
     command:name: No schedules were due
     myTestCommand:name: No schedules were due
     cache:clean: /usr/bin/env php /Users/myUser/myApp/artisan cache:clean > /dev/null &
     mail:subscribers: /usr/bin/env php /Users/myUser/myApp/artisan mail:subscribers > /dev/null &