PHPackages                             tourze/async-command-bundle - 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. tourze/async-command-bundle

ActiveSymfony-bundle[CLI &amp; Console](/categories/cli)

tourze/async-command-bundle
===========================

异步执行Command

v1.0.2(6mo ago)011.5k5MITPHPCI passing

Since Jun 3Pushed 5mo agoCompare

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

READMEChangelog (4)Dependencies (18)Versions (5)Used By (5)

AsyncCommandBundle
==================

[](#asynccommandbundle)

[English](README.md) | [中文](README.zh-CN.md)

[![PHP Version](https://camo.githubusercontent.com/de9130b50f5f66990284541e0ae13bea183a2bf09ed19c954900eb977755446a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f6173796e632d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/async-command-bundle)[![Latest Version](https://camo.githubusercontent.com/0c08ed66d2b77e449c620eb6cec8c371f8f9f09ce0ce3965fbc3781617c65d85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f6173796e632d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/async-command-bundle)[![License](https://camo.githubusercontent.com/b4f0b911b8dcafb9b838caf6e8a2edefffe2332641b3154251a0f3658080c7ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f6173796e632d636f6d6d616e642d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/async-command-bundle)[![Build Status](https://camo.githubusercontent.com/0a217d08e8110c1f432e58a9f309184d7236a483280c8998fd126312b58f2cd1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746f75727a652f6173796e632d636f6d6d616e642d62756e646c652f43492f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/tourze/async-command-bundle/actions)[![Code Coverage](https://camo.githubusercontent.com/fc4a8bc7a883e43c5f085a2e58f3aed1f29748776dd2a777a1d17a62eb448e19/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f6173796e632d636f6d6d616e642d62756e646c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/async-command-bundle)

A Symfony bundle for executing console commands asynchronously using Symfony Messenger.

Features
--------

[](#features)

- Execute Symfony console commands asynchronously
- Built-in error handling and logging
- Support for command options and arguments
- Seamless integration with Symfony Messenger

Dependencies
------------

[](#dependencies)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- Symfony Messenger component
- Monolog for logging

Installation
------------

[](#installation)

Add this bundle to your Symfony project:

```
composer require tourze/async-command-bundle
```

Quick Start
-----------

[](#quick-start)

### 1. Enable the bundle

[](#1-enable-the-bundle)

Add the bundle to your `config/bundles.php`:

```
return [
    // ... other bundles
    Tourze\AsyncCommandBundle\AsyncCommandBundle::class => ['all' => true],
];
```

### 2. Configure Messenger

[](#2-configure-messenger)

Configure Symfony Messenger to handle the async command messages:

```
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async:
                dsn: 'doctrine://default'
        routing:
            'Tourze\AsyncCommandBundle\Message\RunCommandMessage': async
```

### 3. Dispatch commands asynchronously

[](#3-dispatch-commands-asynchronously)

```
use Symfony\Component\Messenger\MessageBusInterface;
use Tourze\AsyncCommandBundle\Message\RunCommandMessage;

class SomeService
{
    public function __construct(
        private MessageBusInterface $messageBus
    ) {
    }

    public function scheduleCommand(): void
    {
        $message = new RunCommandMessage();
        $message->setCommand('app:some-command');
        $message->setOptions([
            '--env' => 'prod',
            '--force' => true,
            'argument1' => 'value1'
        ]);

        $this->messageBus->dispatch($message);
    }
}
```

Configuration
-------------

[](#configuration)

The bundle works out of the box with minimal configuration. The command handler will:

- Log command execution start and completion
- Handle exceptions gracefully
- Support command retries through Symfony Messenger's retry mechanism

Advanced Usage
--------------

[](#advanced-usage)

### Using the AsyncCommandService

[](#using-the-asynccommandservice)

For a more convenient way to dispatch commands, you can use the `AsyncCommandService`:

```
use Tourze\AsyncCommandBundle\Service\AsyncCommandService;

class MyService
{
    public function __construct(
        private AsyncCommandService $asyncCommandService
    ) {
    }

    public function scheduleCommand(): void
    {
        $this->asyncCommandService->runCommand('app:some-command', [
            '--env' => 'prod',
            '--force' => true,
            'argument1' => 'value1'
        ]);
    }
}
```

### Error Handling and Retries

[](#error-handling-and-retries)

Configure retry behavior in your messenger configuration:

```
# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            async:
                dsn: 'doctrine://default'
                retry_strategy:
                    max_retries: 3
                    delay: 1000
                    multiplier: 2
        routing:
            'Tourze\AsyncCommandBundle\Message\RunCommandMessage': async
```

### Logging Configuration

[](#logging-configuration)

The bundle uses Monolog for logging. You can configure the logger channel:

```
# config/packages/monolog.yaml
monolog:
    channels: ['async_command']
    handlers:
        async_command:
            type: stream
            path: "%kernel.logs_dir%/async_command.log"
            level: info
            channels: ['async_command']
```

API Reference
-------------

[](#api-reference)

### RunCommandMessage

[](#runcommandmessage)

The message class used to dispatch command execution:

```
class RunCommandMessage implements AsyncMessageInterface
{
    public function getCommand(): string;
    public function setCommand(string $command): void;
    public function getOptions(): array;
    public function setOptions(array $options): void;
}
```

### RunCommandHandler

[](#runcommandhandler)

The message handler that executes commands:

- Decorated with `#[AsMessageHandler]` attribute
- Accepts optional `LoggerInterface` for logging
- Handles both recoverable and non-recoverable exceptions

Error Handling
--------------

[](#error-handling)

The bundle provides robust error handling:

- **Recoverable exceptions**: Re-thrown to allow Messenger retry mechanism
- **Non-recoverable exceptions**: Logged as errors but do not cause message failure
- **Logging**: All command executions are logged with context information

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/async-command-bundle/tests
```

Run PHPStan static analysis:

```
./vendor/bin/phpstan analyse packages/async-command-bundle
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to this project.

### Development Guidelines

[](#development-guidelines)

1. Follow PSR-12 coding standards
2. Write unit tests for new features
3. Ensure all tests pass
4. Update documentation as needed

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for details on version history and changes.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance71

Regular maintenance activity

Popularity19

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 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 ~54 days

Total

4

Last Release

185d ago

Major Versions

0.0.1 → 1.0.02025-10-31

### Community

Maintainers

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

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-async-command-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-async-command-bundle/health.svg)](https://phpackages.com/packages/tourze-async-command-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[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)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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