PHPackages                             xactsystems/command-scheduler - 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. xactsystems/command-scheduler

ActiveSymfony-bundle

xactsystems/command-scheduler
=============================

A Symfony command scheduler.

v5.0.6(1y ago)01.0k[2 issues](https://github.com/XactSystems/command-scheduler/issues)MITPHPPHP &gt;=8.1

Since Jul 24Pushed 1y agoCompare

[ Source](https://github.com/XactSystems/command-scheduler)[ Packagist](https://packagist.org/packages/xactsystems/command-scheduler)[ RSS](/packages/xactsystems-command-scheduler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (25)Versions (48)Used By (0)

XactCommandScheduler
====================

[](#xactcommandscheduler)

This bundle allows you to provide job scheduling via a list of jobs configured within a DBAL store.

Jobs can be created for once-only jobs as well as repeating jobs based on a cron expression. The bundle features an admin interface for management of the scheduled commands as well as via the CommandScheduler class.

Documentation
-------------

[](#documentation)

### 1) Add XactCommandScheduler to your project

[](#1-add-xactcommandscheduler-to-your-project)

```
composer require xactsystems/command-scheduler
```

### 2) Create the scheduler table

[](#2-create-the-scheduler-table)

```
php bin/console doctrine:schema:create
```

### 3) Add the routes for the scheduler admin views

[](#3-add-the-routes-for-the-scheduler-admin-views)

config/routes.yaml

```
command_scheduler:
    resource: "@XactCommandSchedulerBundle/Resources/config/routing.yaml"
```

### 4) Use the admin views

[](#4-use-the-admin-views)

Browse to

### 5) Run the command scheduler

[](#5-run-the-command-scheduler)

```
php bin/console xact:command-scheduler
```

The command accepts the following options:

- `--max-runtime=nnn` Sets the maximum length in seconds the scheduler will run for. 0 (default) runs forever.
- `--idle-time=nnn` Sets the number of seconds the scheduler sleeps for when the command queue is empty. Defaults to 5.

Manage the scheduler via code
-----------------------------

[](#manage-the-scheduler-via-code)

### Add a scheduled command

[](#add-a-scheduled-command)

```
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
use Cron\CronExpression;
...

public function myControllerAction(CommandScheduler $scheduler)
{
    $scheduledCommand = new ScheduledCommand();
    $scheduledCommand->setDescription('My daily command');
    $scheduledCommand->setCommand( 'app:my-daily-command' );
    $scheduledCommand->setCronExpression( CronExpression::factory('@daily') );
    $scheduledCommand->setPriority(5);  // Defaults to 1
    $scheduler->add( $scheduledCommand );
}
```

### Disable a command

[](#disable-a-command)

```
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...

public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
    $scheduler->disable($commandId);
}
```

### Run a command immediately

[](#run-a-command-immediately)

```
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...

public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
    $scheduler->runImmediately($commandId);
}
```

### Delete a command

[](#delete-a-command)

```
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...

public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
    $scheduler->delete($commandId);
}
```

### Get a list of active commands

[](#get-a-list-of-active-commands)

```
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...

public function myControllerAction(CommandScheduler $scheduler)
{
    $commands = $scheduler->getActive();
    foreach ($commands as $command) {
        ...
    }
}
```

### Creating commands via the CommandSchedulerFactory

[](#creating-commands-via-the-commandschedulerfactory)

When using the factory, you can set the the configuration values for the following command settings:

```
#config/bundles/xact_command_scheduler.yml

xact_command_scheduler:
    clear_data: ~          # Defaults to true
    retry_on_fail: ~       # Defaults to false
    retry_delay: ~         # Defaults to 60
    retry_max_attempts: ~  # Defaults to 60
```

You can then use the factory methods to create your scheduled commands. The configured parameters above will be set on commands created via factory methods unless overwritten in the method calls:

```
use Xact\CommandScheduler\CommandSchedulerFactory;

class MyController extends AbstractController
{
    private CommandSchedulerFactory $commandFactory;

    public function __controller(CommandSchedulerFactory $commandFactory) {
        $this->commandFactory = $commandFactory;
    }

    public function myEmailAction(EntityManagerInterface $em) {
        $myLargeDataObject = 'Some enormous serialized value you want to store in the command and probably delete once the command is complete.';
        $command = $this->commandFactory->createImmediateCommand(
            'My test command',
            'app:test-command',
            null,
            $myLargeDataObject,
        );
        $em->persist($command);
        $em->flush();
    }
}
```

#### Factory methods:

[](#factory-methods)

```
    /**
     * Create a command to run immediately
     *
     * @param string[]|null $arguments
     * @param bool|null $clearData If null, the configuration value 'clear_data' is used. Default true.
     * @param bool|null $retryOnFail If null, the configuration value 'retry_on_fail' is used. Default false.
     * @param int|null $retryDelay If null, the configuration value 'retry_delay' is used. Default 60.
     * @param int|null $retryMaxAttempts If null, the configuration value 'retry_max_attempts' is used. Default 60.
     */
    public function createImmediateCommand(
        string $description,
        string $command,
        ?array $arguments = null,
        ?string $data = null,
        ?bool $clearData = null,
        ?bool $retryOnFail = null,
        ?int $retryDelay = null,
        ?int $retryMaxAttempts = null
    ): ScheduledCommand {}

    /**
     * Create a command scheduled by a CRON expression
     *
     * @param string[]|null $arguments
     * @param bool|null $clearData If null, the configuration value 'clear_data' is used. Default true.
     * @param bool|null $retryOnFail If null, the configuration value 'retry_on_fail' is used. Default false.
     * @param int|null $retryDelay If null, the configuration value 'retry_delay' is used. Default 60.
     * @param int|null $retryMaxAttempts If null, the configuration value 'retry_max_attempts' is used. Default 60.
     */
    public function createCronCommand(
        string $cronExpression,
        string $description,
        string $command,
        ?array $arguments = null,
        ?string $data = null,
        ?bool $clearData = null,
        ?bool $retryOnFail = null,
        ?int $retryDelay = null,
        ?int $retryMaxAttempts = null
    ): ScheduledCommand {}
```

Cron notes
----------

[](#cron-notes)

The bundle uses dragonmantank/cron-expression CronExpression class to determine run times and you can use the non-standard pre-defined scheduling definitions. See [Cron Format](https://en.wikipedia.org/wiki/Cron#Format) for more details.

Credits
-------

[](#credits)

- Ian Foulds as the creator of this package.
- Piotr Nowak () for inspiration when trying to find a replacement for jms/job-queue-bundle - [schmittjoh/JMSJobQueueBundle#208 (comment)](https://github.com/schmittjoh/JMSJobQueueBundle/issues/208#issuecomment-393069592).
- Julien Guyon () for inspiration with his command scheduler bundle.

License
-------

[](#license)

This bundle is released under the MIT license. See the complete license in the bundle:

[LICENSE](https://github.com/xactsystems/command-scheduler/blob/master/LICENSE)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~33 days

Recently: every ~3 days

Total

47

Last Release

605d ago

Major Versions

3.4.1.x-dev → 4.4.52022-04-30

3.4.22 → 4.4.x-dev2022-08-04

3.6.3 → 4.4.72023-04-17

3.x-dev → 4.5.02023-06-13

v4.5.3 → v5.0.02024-08-29

PHP version history (5 changes)v3.4.0PHP ^7.0

3.4.1PHP ^7.1

4.4.5PHP ^7.4

4.5.x-devPHP &gt;=7.4.12

v5.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfec2e953df9e01a16d4cebd810aebc86832067d8a55df8c546c3917a5e89465?d=identicon)[ianef](/maintainers/ianef)

---

Top Contributors

[![ianef](https://avatars.githubusercontent.com/u/5128087?v=4)](https://github.com/ianef "ianef (104 commits)")

---

Tags

command-schedulercroncron-expressionhacktoberfestjob-schedulingschedulersymfony

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/xactsystems-command-scheduler/health.svg)

```
[![Health](https://phpackages.com/badges/xactsystems-command-scheduler/health.svg)](https://phpackages.com/packages/xactsystems-command-scheduler)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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