- Can I use this package directly in a standard Laravel app (non-Octane) for HTTP requests?
- No, this package is designed for ReactPHP’s event-driven architecture, which conflicts with Laravel’s synchronous PHP-FPM stack. You’d need Laravel Octane (Swoole/RoadRunner) or a separate CLI process to host ReactPHP workers. For HTTP, consider Laravel’s built-in HTTP client or Symfony’s `http-client` instead.
- How do I integrate this with Laravel Octane for WebSocket connections?
- In Laravel Octane, use this package inside a Swoole worker to decorate your WebSocket connector. Wrap the base `react/socket` connector with decorators like `Repeat` or `Timeout` in your Octane worker’s event loop. Ensure your Octane config enables Swoole’s async mode. Example: `$connector = new Repeat(new Timeout(new SocketConnector(), 5));`
- Does this package support PHP 8.5+ and Laravel 10+?
- The package supports PHP 8.1+, but PHP 8.5+ may introduce risks if it relies on deprecated ReactPHP APIs. Test thoroughly for conflicts with Laravel’s OpCache/JIT or Symfony components (e.g., `symfony/http-client`). Check the [ReactPHP changelog](https://github.com/reactphp/socket) for breaking changes. Laravel 10+ requires PHP 8.1+, so version skew is less likely.
- What’s the best way to handle connection retries in Laravel Queues with this package?
- For Laravel Queues, use this package in a separate ReactPHP worker process (managed by Supervisor) to handle async retries. Bridge Laravel’s sync queues to ReactPHP via Redis or RabbitMQ. Example: Decorate your Redis connector with `Repeat` and `Delay` to implement exponential backoff. Avoid mixing ReactPHP and Laravel’s sync queue drivers directly.
- Are there performance benchmarks comparing this to Laravel Octane’s built-in async features?
- No official benchmarks exist, but ReactPHP’s event loop is generally lighter for high-concurrency async tasks than Swoole/RoadRunner in Octane. For HTTP workloads, Octane’s Swoole may outperform this package. For background jobs or WebSockets, test both in isolation using tools like `ab` or `k6` to compare latency/throughput. ReactPHP excels in I/O-bound tasks like WebSockets or gRPC.
- How do I configure concurrent connections with a limit (e.g., 10 max connections)?
- Use the `Concurrent` decorator to limit concurrent connections. Pass your base connector and a max count: `$connector = new Concurrent(new SocketConnector(), 10);`. This ensures no more than 10 connections are established simultaneously. Combine with `Repeat` for retries if connections fail. Example: `$connector->connect('tcp://example.com:1234')->then(...)`.
- Will this package work with Laravel’s default Apache/Nginx + PHP-FPM setup?
- No, this package requires ReactPHP’s event loop, which cannot run in PHP-FPM. You must isolate it in a separate process (e.g., CLI script, Docker container, or Laravel Octane worker). For HTTP requests, use Laravel’s `Http` facade or Symfony’s `http-client`. For async tasks, consider Laravel Queues with a ReactPHP worker or a message broker like Redis.
- What are the alternatives to this package for Laravel async connections?
- For Laravel, prioritize built-in solutions: **Laravel Octane** (Swoole/RoadRunner) for async HTTP, **Laravel Queues** with Redis/RabbitMQ for background jobs, or **Symfony’s `http-client`** for HTTP requests. If you need ReactPHP-specific features, consider **react/http-client** or **spatie/react-socketio-client** for WebSockets. Avoid mixing ReactPHP with Laravel’s sync stack unless absolutely necessary.
- How do I add a delay before retrying a failed connection?
- Combine the `Repeat` and `Delay` decorators. Example: `$connector = new Repeat(new Delay(new SocketConnector(), 1000), 3);`. This retries failed connections 3 times with a 1-second delay between attempts. Adjust the delay (in milliseconds) and retry count as needed. For exponential backoff, chain multiple `Delay` decorators with increasing intervals.
- Does this package support selective routing (e.g., route connections based on URI)?
- Yes, use the `Selective` decorator to filter connections by URI or other rules. Example: `$connector = new Selective(new SocketConnector(), function ($uri) { return strpos($uri, 'secure') !== false; });`. This decorator rejects connections that don’t match your criteria. Combine with `Swappable` to dynamically switch connectors based on routing logic.