- How can I use boson-php/runtime for Laravel background jobs instead of queues?
- This package can replace or extend Laravel’s queue system by treating Boson tasks as discrete jobs. Register a Boson worker as a Laravel queue job (e.g., `boson:process`) and dispatch it via `dispatch(new BosonJob($payload))`. Ensure your Boson runtime is configured to handle serialization/deserialization compatible with Laravel’s job payloads.
- Does boson-php/runtime integrate with Laravel’s service container (PSR-11) natively?
- No, but you can manually bind Boson services in Laravel’s `AppServiceProvider` using `$this->app->singleton(BosonRuntime::class, fn() => new BosonRuntime(config('boson')))`. This allows dependency injection for Boson clients or event handlers. For full PSR-11 compliance, wrap the runtime in a container-aware adapter.
- What Laravel versions does boson-php/runtime support?
- The package itself is PHP 8.4+ only, but Laravel compatibility depends on your setup. Test with Laravel 10+ for best results, as older versions may lack PHP 8.4 features. Check the [Laravel adapter docs](https://bosonphp.com/doc/0.19/laravel-adapter) for version-specific guidance.
- How does boson-php/runtime handle serialization for Laravel APIs?
- Boson uses its own serialization format by default (not JSON), which may conflict with Laravel’s JSON APIs. Configure the runtime to use JSON or Protocol Buffers via `BosonRuntime::setSerializer()`. For APIs, transform Boson responses to Laravel-compatible formats (e.g., `json_encode()`) before returning them.
- Can I use this package for real-time WebSocket events in Laravel Echo?
- Yes, but you’ll need to bridge Boson events to Laravel Echo manually. Subscribe to Boson’s event bus in a service provider, then emit Laravel events (e.g., `Event::dispatch(new BosonEvent($data))`). Use Laravel Echo’s `Broadcast` trait to push events to WebSocket clients. Monitor for serialization mismatches.
- What happens if the Boson runtime crashes in production?
- By default, crashes will terminate the process. To improve resilience, wrap Boson operations in a `try-catch` block and log errors via Laravel’s `Log::error()`. For critical tasks, implement retry logic using Laravel’s `retry()` helper or a queue job with exponential backoff.
- Are there alternatives to boson-php/runtime for Laravel event-driven workflows?
- For event processing, consider `spatie/async-jobs` (for async tasks) or `laravel-websockets/laravel-websockets` (for real-time). If you need RPC-like functionality, `php-rpc/rpc` or Laravel’s built-in HTTP clients may suffice. Boson’s strength lies in its WebView runtime for complex, stateful workflows.
- How do I configure boson-php/runtime for a Laravel microservice?
- Start by publishing Boson’s config (if supported) or define it in `config/boson.php`. Use Laravel’s `config()` helper to access settings. For modularity, isolate Boson logic in a dedicated module (e.g., `nwidart/laravel-modules`) and bind it to Laravel’s container. Test inter-service communication with Laravel’s HTTP clients.
- Does boson-php/runtime work with Laravel’s Horizon for queue monitoring?
- Not directly, but you can integrate Horizon by extending its `MonitorProcesses` class to track Boson workers. Expose Boson job metrics via Laravel’s `Monitor` facade or a custom API endpoint. Ensure your Boson runtime logs job statuses in a Horizon-compatible format (e.g., JSON with `job` and `payload` fields).
- How do I test boson-php/runtime in a Laravel project?
- Mock Boson dependencies using Laravel’s `Mockery` or PHPUnit’s `createMock()`. Test runtime behavior by injecting a fake Boson client in your service provider. For integration tests, use Laravel’s `Http::fake()` to simulate Boson responses. Validate serialization/deserialization with `assertJson()` or custom assertions for Boson-specific formats.