PHPackages                             package-of-laravel/dispatcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. package-of-laravel/dispatcher

ActiveLibrary[CLI &amp; Console](/categories/cli)

package-of-laravel/dispatcher
=============================

Schedule your artisan commands within your application's source code

v1.5.0(2y ago)05MITPHPPHP &gt;=5.3.2

Since Mar 6Pushed 2y agoCompare

[ Source](https://github.com/package-of-laravel/dispatcher)[ Packagist](https://packagist.org/packages/package-of-laravel/dispatcher)[ RSS](/packages/package-of-laravel-dispatcher/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (21)Used By (0)

Dispatcher
==========

[](#dispatcher)

Dispatcher allows you to schedule your artisan commands within your [Laravel](http://laravel.com) project, eliminating the need to touch the crontab when deploying. It also allows commands to run per environment and keeps your scheduling logic where it should be, in your version control.

[![](https://camo.githubusercontent.com/baf907db1face08a2e3563c008264c97a078589e5e2258b9fcc277691ee1cb0c/68747470733a2f2f73332d75732d776573742d322e616d617a6f6e6177732e636f6d2f6f73732d617661746172732f646973706174636865725f726f756e645f726561646d652e706e67)](https://camo.githubusercontent.com/baf907db1face08a2e3563c008264c97a078589e5e2258b9fcc277691ee1cb0c/68747470733a2f2f73332d75732d776573742d322e616d617a6f6e6177732e636f6d2f6f73732d617661746172732f646973706174636865725f726f756e645f726561646d652e706e67)

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

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

---

[![Latest Stable Version](https://camo.githubusercontent.com/7a5df8e73e29f26d0c22b70c4d27e2b22be63b2f0bd925ec8e0bde1824f32e09/68747470733a2f2f706f7365722e707567782e6f72672f696e64617475732f646973706174636865722f762f737461626c652e706e67)](https://packagist.org/packages/indatus/dispatcher) [![Total Downloads](https://camo.githubusercontent.com/e1b9e898bb5252efc4b1b800cd36e940e30ed90eff50825f8fd94e806fce233c/68747470733a2f2f706f7365722e707567782e6f72672f696e64617475732f646973706174636865722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/indatus/dispatcher) [![Build Status](https://camo.githubusercontent.com/8362b692bce8e4d5888b8047b0e1844fd0bb1e3205737c7fbedca43876ae5e7d/68747470733a2f2f7472617669732d63692e6f72672f496e64617475732f646973706174636865722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Indatus/dispatcher) [![Code Coverage](https://camo.githubusercontent.com/cfee67a9f706b75ba062a46ea46b55133aa6051b48bc934a67970f0ed1cf5de4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f496e64617475732f646973706174636865722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Indatus/dispatcher/?branch=master) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/e76b367f0540c76c9b3932a0b8f1c01ed9669b158fa817473abbf976c802291c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f496e64617475732f646973706174636865722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Indatus/dispatcher/?branch=master)

README Contents
---------------

[](#readme-contents)

- [Features](#features)
- [Tutorial](#tutorial)
- [Installation](#installation)
    - [For Laravel 4 (see 1.4 branch)](https://github.com/Indatus/dispatcher/tree/1.4#installation)
    - [For Laravel 5](#installation) - discontinued, see [Laravel 5's scheduler](http://laravel-news.com/2014/11/laravel-5-scheduler/)
    - [Upgrading from 1.4 to 2.0](#upgrading-1.4-2.0)
- [Usage](#usage)
    - [Generating New Scheduled Commands](#new-commands)
    - [Scheduling Existing Commands](#scheduling-commands)
    - [Running Commands As Users](#commands-as-users)
    - [Environment-Specific Commands](#environment-commands)
    - [Running Commands In Maintenance Mode](#maintenance-mode)
    - [Advanced Scheduling](#advanced-scheduling)
- [Drivers](#drivers)
    - [DateTime](#datetime)
- [Custom Drivers](#custom-drivers)
- [FAQ](#faq)

\## Features - Schedule artisan commands to run automatically
- Scheduling is maintained within your version control system
- Single source of truth for when and where commands run
- Schedule commands to run with arguments and options
- Run commands as other users
- Run commands in certain environments
- Use custom drivers for custom scheduling contexts

\## Tutorial By Ben Kuhl at the [Laravel Louisville meetup](http://laravel-louisville.github.io/meetup/) ([@lurvul](https://twitter.com/lurvul)): [Video](http://vimeo.com/94212203) - [Slides](http://bkuhl.github.io/dispatcher-slides)

By Jefferey Way at [Laracasts](https://www.laracasts.com): [Recurring Tasks the Laravel Way](https://laracasts.com/lessons/recurring-tasks-the-laravel-way)

\## Installation > **NOTICE: [Laravel 5 now includes scheduling](http://laravel-news.com/2014/11/laravel-5-scheduler/) out of the box. This package will no longer be maintained for Laravel 5 and above**

Requirements1.4.\*2.\*[Laravel](http://laravel.com)4.1/4.25.x[PHP](https://php.net)5.3+5.4+[HHVM](http://hhvm.com)3.3+3.3+Install with Composer...~1.4~2.0@dev> If you're using **Laravel 4** view the [readme in the 1.4 branch](https://github.com/Indatus/dispatcher/tree/1.4)

Add this line to the providers array in your `config/app.php` file :

```
        'Indatus\Dispatcher\ServiceProvider',
```

Add the following to your root Crontab (via `sudo crontab -e`):

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

If you are adding this to `/etc/cron.d` you'll need to specify a user immediately after `* * * * *`.

> You may add this to any user's Crontab, but only the root crontab can run commands as other users.

\### Upgrading from 1.4 to 2.0 In all scheduled commands...

- Replace `use Indatus\Dispatcher\Drivers\Cron\Scheduler` with `use Indatus\Dispatcher\Drivers\DateTime\Scheduler`
- Replaced uses of `Scheduler::[DAY_OF_WEEK]` with `Day::[DAY_OF_WEEK]` and `Scheduler::[MONTH_OF_YEAR]` with `Month::[MONTH_OF_YEAR]`
- `executable` config option has been removed. Dispatcher now inherits the [path to the binary](http://php.net/manual/en/reserved.constants.php#constant.php-binary) that was initially used to run `scheduled:run`

\## Usage ```
scheduled
  scheduled:make              Create a new scheduled artisan command
  scheduled:run               Run scheduled commands
  scheduled:summary           View a summary of all scheduled artisan commands

```

If commands are not visible via `php artisan` then they cannot be scheduled.

\### Generating New Scheduled Commands Use `php artisan scheduled:make` to generate a new scheduled command, the same way you would use artisan's `command:make`. Then [register your command](http://laravel.com/docs/commands#registering-commands) with Laravel.

\### Scheduling Existing Commands You may either implement `\Indatus\Dispatcher\Scheduling\ScheduledCommandInterface` or follow the below steps.

1. Add use statements to your command. If you're using a custom driver you will use a different `Scheduler` class.

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

2. Extend `\Indatus\Dispatcher\Scheduling\ScheduledCommand`
3. Implement schedule():

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

For details and examples on how to schedule, see the [DateTime Driver](#datetime).

\### Running Commands As Users You may override `user()` to run a given artisan command as a specific user. Ensure your `scheduled:run` artisan command is running as root.

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

> This feature may not be supported by all drivers.

\### Environment-Specific Commands You may override `environment()` to ensure your command is only scheduled in specific environments. It should provide a single environment or an array of environments.

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

\### Maintenance Mode By default, cron commands will *not* run when application is in Maintenance Mode. This will prevent all sorts of weird output that might occur if a cron command is run while you are migrating a database or doing a composer update.

You may override `runInMaintenanceMode()` to force your command to still be run while the application is in maintenance mode.

```
    public function runInMaintenanceMode()
    {
        return true;
    }
```

\### Advanced scheduling You may schedule a given command to to run at multiple times by `schedule()` returning multiple `Schedulable` instances.

```
	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)
        ];
    }
```

You may also schedule a command to run with arguments and options.

```
	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)
        ];
	}
```

> NOTE: Both `args()` and `opts()`, whichever is called first, will internally create a new `Schedulable` instance for you so you don't need to `App::make()`.

\## Drivers Drivers provide the ability to add additional context to your scheduling. [Building custom drivers](#custom-drivers) is a great way to customize this context to your application's needs.

\### DateTime (Default) Examples of how to schedule:

```
	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);
    }
```

\## Custom Drivers Custom drivers allow you to provide application context within scheduling. For example, an education-based application may contain scheduling methods like `inServiceDays()`, `springBreak()` and `christmasBreak()` where commands are run or don't run during those times.

Create a packagepath such as `\MyApp\ScheduleDriver\` and create two classes:

- `Scheduler` that `implements Indatus\Dispatcher\Scheduling\Schedulable`. This class should provide a useful interface for programmers to schedule their commands.
- `ScheduleService` that `extends \Indatus\Dispatcher\Services\ScheduleService`. This class contains logic on how to determine if a command is due to run.

Publish the configs using `php artisan config:publish indatus/dispatcher`. Then update your driver configuration to reference the package in which these 2 classes are included (do not include a trailing slash):

```
    'driver' => '\MyApp\ScheduleDriver'

```

\## FAQ **I need to deploy to multiple servers representing a single environment. How can I be sure my command is only run by a single server and not run on each server?**

Schedule `scheduled:run` to run every minute with [rcron](https://code.google.com/p/rcron/):

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

**Why are my commands not running when I've scheduled them correctly? I'm also not seeing any error output**

1. Verify that mcrypt is installed and working correctly via the command `php -i | mcrypt`.
2. Utilizing `php artisan scheduled:run --debug` will tell you why they're not running. If you do not see your command listed here then it is not set up correctly.

Example:

```
$ 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 &

```

**I have commands that extend `ScheduledCommand` but why don't they appear in when I run `scheduled:summary`?**

Commands that are disabled will not appear here. Check and be sure `isEnabled()` returns true on those commands.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 81.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~190 days

Recently: every ~808 days

Total

19

Last Release

1019d ago

PHP version history (3 changes)1.0PHP &gt;=5.4.0

v1.1.1PHP &gt;=5.3.2

v1.4.2PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/84123?v=4)[Arlen Walker](/maintainers/paladin)[@Paladin](https://github.com/Paladin)

---

Top Contributors

[![bkuhl](https://avatars.githubusercontent.com/u/524933?v=4)](https://github.com/bkuhl "bkuhl (87 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (11 commits)")[![valorin](https://avatars.githubusercontent.com/u/897369?v=4)](https://github.com/valorin "valorin (2 commits)")[![djekl](https://avatars.githubusercontent.com/u/1119714?v=4)](https://github.com/djekl "djekl (1 commits)")[![developeryamhi](https://avatars.githubusercontent.com/u/655072?v=4)](https://github.com/developeryamhi "developeryamhi (1 commits)")[![nbourguig](https://avatars.githubusercontent.com/u/276832?v=4)](https://github.com/nbourguig "nbourguig (1 commits)")[![opb](https://avatars.githubusercontent.com/u/778850?v=4)](https://github.com/opb "opb (1 commits)")[![pralhadstha](https://avatars.githubusercontent.com/u/6309194?v=4)](https://github.com/pralhadstha "pralhadstha (1 commits)")[![Schnoop](https://avatars.githubusercontent.com/u/1263407?v=4)](https://github.com/Schnoop "Schnoop (1 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (1 commits)")

---

Tags

laravelartisanscheduledispatcher

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/package-of-laravel-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/package-of-laravel-dispatcher/health.svg)](https://phpackages.com/packages/package-of-laravel-dispatcher)
```

###  Alternatives

[indatus/dispatcher

Schedule your artisan commands within your application's source code

1.1k855.3k2](/packages/indatus-dispatcher)[guratr/nova-command-runner

Laravel Nova tool for running Artisan commands.

43232.8k1](/packages/guratr-nova-command-runner)[sunaoka/laravel-facade-generator

Provide command line generation of facade layer files.

171.9k](/packages/sunaoka-laravel-facade-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
