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

ActiveSymfony-bundle

tourze/symfony-aop-async-bundle
===============================

Async AOP Bundle for Symfony

1.0.1(6mo ago)04.2k9MITPHPCI passing

Since Jun 14Pushed 4mo agoCompare

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

READMEChangelog (4)Dependencies (17)Versions (5)Used By (9)

symfony-aop-async-bundle
========================

[](#symfony-aop-async-bundle)

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

[![Latest Version](https://camo.githubusercontent.com/022afec8df4580142e957e595c8b2d9dfc622afe2c15c7c5398246e6ab19f3f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f73796d666f6e792d616f702d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-async-bundle)[![Total Downloads](https://camo.githubusercontent.com/9fc09693d8433d671d33a9c143ddd71022b7ed5eb4bc30a476eddc79bbf6076c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f73796d666f6e792d616f702d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-async-bundle)[![PHP Version](https://camo.githubusercontent.com/b9370eae5088e5c0ca7a8c25175422215ef5d19bafb06cb1381b619a579438fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f73796d666f6e792d616f702d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-async-bundle)[![License](https://camo.githubusercontent.com/24564845afdcc75f8a4f3fd6db0d721d8932b5e5c73668f3596d54e45d2bb5d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f73796d666f6e792d616f702d6173796e632d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/symfony-aop-async-bundle)[![Coverage Status](https://camo.githubusercontent.com/73ee3bab50824f778cedc6b4b3f78bcdab621eef812a979ec388b8ad692a4bff/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)

A Symfony bundle that provides asynchronous method execution using AOP (Aspect-Oriented Programming) and Symfony Messenger.

Features
--------

[](#features)

- **Easy async execution**: Mark any public method with `#[Async]` attribute to execute asynchronously
- **AOP-based implementation**: Uses aspect-oriented programming for clean and transparent async execution
- **Symfony Messenger integration**: Leverages Symfony Messenger for reliable message processing
- **Configurable retry and delay**: Support for retry count and execution delay
- **Graceful fallback**: Falls back to synchronous execution if async dispatch fails

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

[](#installation)

```
composer require tourze/symfony-aop-async-bundle
```

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

[](#quick-start)

1. **Enable the bundle** in your `config/bundles.php`:

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

2. **Mark methods for async execution**:

```
use Tourze\Symfony\AopAsyncBundle\Attribute\Async;

class EmailService
{
    #[Async]
    public function sendWelcomeEmail(string $userEmail): void
    {
        // This method will be executed asynchronously
        // Send email logic here...
    }

    #[Async(retryCount: 3, delayMs: 5000)]
    public function processLargeDataset(array $data): void
    {
        // This method will be retried up to 3 times
        // and delayed by 5 seconds before execution
    }
}
```

3. **Use the service normally**:

```
class UserController extends AbstractController
{
    public function register(EmailService $emailService): Response
    {
        // This call returns immediately, email is sent asynchronously
        $emailService->sendWelcomeEmail('user@example.com');

        return new Response('User registered successfully');
    }
}
```

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

[](#configuration)

### Async Attribute Options

[](#async-attribute-options)

The `#[Async]` attribute supports the following options:

- `retryCount` (int, default: 0): Number of times to retry the method if it fails
- `delayMs` (int, default: 0): Delay in milliseconds before executing the method

```
#[Async(retryCount: 5, delayMs: 10000)]
public function criticalTask(): void
{
    // This task will be retried up to 5 times
    // and delayed by 10 seconds before execution
}
```

### Messenger Configuration

[](#messenger-configuration)

Configure Symfony Messenger in your `config/packages/messenger.yaml`:

```
framework:
    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
        routing:
            'Tourze\AsyncServiceCallBundle\Message\ServiceCallMessage': async
```

Limitations
-----------

[](#limitations)

To keep the implementation simple, the following limitations apply:

1. **Public methods only**: The `#[Async]` attribute only works on public methods due to AOP limitations
2. **Object serialization**: Complex nested objects and object arrays may not serialize properly
3. **No transaction inheritance**: Async methods don't inherit database transactions
4. **Exception handling**: Exceptions in async methods are logged but not propagated to the caller

How It Works
------------

[](#how-it-works)

1. When a method marked with `#[Async]` is called, the AsyncAspect intercepts the call
2. The method call is serialized into a ServiceCallMessage
3. The message is dispatched to Symfony Messenger with optional delay/retry stamps
4. The original method call returns immediately without executing the method body
5. The message is processed asynchronously by a Messenger worker
6. If async dispatch fails, the method falls back to synchronous execution

Testing
-------

[](#testing)

Run the test suite:

```
./vendor/bin/phpunit packages/symfony-aop-async-bundle/tests
```

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

[](#dependencies)

This bundle requires:

- `tourze/symfony-aop-bundle`: Provides AOP functionality
- `tourze/async-service-call-bundle`: Handles async service calls
- `symfony/messenger`: Message queue system

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

[](#contributing)

Please see [CONTRIBUTING.md](../../CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please create an issue in our [GitHub repository](https://github.com/tourze/php-monorepo/issues).

License
-------

[](#license)

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

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance72

Regular maintenance activity

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

4

Last Release

180d ago

Major Versions

0.0.2 → 1.0.02025-11-01

### Community

Maintainers

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/tourze-symfony-aop-async-bundle/health.svg)](https://phpackages.com/packages/tourze-symfony-aop-async-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)
