robertwesner / simple-mvc-php-spawner-bundle
Run background tasks that do not produce synchronous output or require monitoring.
v1.0.1
2025-06-08 14:34 UTC
Requires
- php: >=8.4
- robertwesner/dependency-injection: ^v1.3.0
- robertwesner/simple-mvc-php: ^0.10.1 || ^0.11.0
Requires (Dev)
- phpunit/phpunit: ^11.3.1
- squizlabs/php_codesniffer: ^3.10.2
README
Simple MVC Spawner Bundle
Run background tasks that do not produce synchronous output or require monitoring.
Fire and forget.
Created for my YouTube playlist viewer with pagination.
Installation
composer require robertwesner/simple-mvc-php-spawner-bundle
Make sure to load the bundle in your $PROJECT_ROOT$/configurations/bundles.php
.
use RobertWesner\SimpleMvcPhp\Configuration; use RobertWesner\SimpleMvcPhpSpawnerBundle\SpawnerBundle; use RobertWesner\SimpleMvcPhpSpawnerBundle\SpawnerBundleConfiguration; Configuration::BUNDLES ::load( SpawnerBundle::class, // optional, can be omitted new SpawnerBundleConfiguration( preExecuteScriptPath: __BASE_DIR__ . '/pre-command.php', ), );
Usage
Create configuration
final readonly class MySpawnConfiguration implements SpawnConfigurationInterface { public function __construct( private string $foo, private string $bar, ) {} public function __serialize(): array { return [ 'foo' => $this->foo, 'bar' => $this->bar, ]; } public function __unserialize(array $data): void { $this->foo = $data['foo']; $this->bar = $data['bar']; } public function getFoo(): string { return $this->foo; } public function getBar(): string { return $this->bar; } }
Create background task
class MySpawn implements SpawnInterface { public function run(SpawnConfigurationInterface|MySpawnConfiguration $configuration): void { // asynchronous task with $configuration->getFoo(), etc... } }
Execute
// spawner accessed through dependency injection $this->spawner->spawn( EchoSpawn::class, new EchoSpawnConfiguration( 'Some value', 'Another value', ), );