toadbeatz/swoole-bundle
A Laravel bundle for running applications on the Swoole PHP extension, enabling high-performance coroutine-based request handling, persistent workers, and faster throughput with simplified setup and configuration.
Install the package via Composer and publish its configuration:
composer require <vendor>/<swoole-bundle> # replace with actual package name
php artisan vendor:publish --tag=swoole-config
Set the required environment variables in .env (host, port, worker count, etc.) and start the Swoole HTTP server:
php artisan swoole:start
Where to look first:
config/swoole.php (or similarly named config) – server, cache, and pool settings.src/Server/HttpServerManager.php – request lifecycle and header/URI validation (critical after v1.3.0).ConnectionPool, PostgreSQLPool, RedisPool) – tune sizes for your workload.First use case: Replace PHP-FPM for a high-traffic Laravel API or microservice. Start by running the HTTP server alone, confirm requests are handled correctly, then progressively enable the Swoole cache adapter and database connection pools. v1.3.0 is the minimum version for production due to security fixes; upgrade immediately if you were on an older release.
HttpServerManager to bootstrap the Laravel kernel and handle concurrent requests. Ensure you are on v1.3.0+ to benefit from CRLF injection protection (headers and URIs are sanitised).SwooleCacheAdapter. Pattern: configure CACHE_DRIVER=swoole (or custom store) and use Laravel’s Cache facade as usual. v1.3.0 disables object deserialization by default (allowed_classes => false); if you cache PHP objects, explicitly whitelist classes in the cache config.ConnectionPool, PostgreSQLPool, or RedisPool to share connections across workers. Pattern: configure pool min/max sizes in config/swoole.php (or database config). v1.3.0 uses atomic counters for thread‑safe size tracking; no code changes needed, but verify pool limits against your database’s max_connections.Swoole\Coroutine\run() or use the package’s coroutine helpers. Avoid mixing blocking extensions (e.g., curl without coroutine hooks).app()->forgetInstance() for scoped bindings, or rely on the package’s built‑in reset if available.Auth, Request, and custom singletons. Test with concurrent requests to catch leakage.header("X-Custom: $input")), test that the new validation doesn’t reject legitimate values. The fix reduces memory allocations, but any non‑standard header format may need adjustment.allowed_classes => false is now the default. If you were caching objects and relying on automatic deserialization, you’ll receive __PHP_Incomplete_Class instances or errors. Fix: whitelist required classes in the cache configuration ('allowed_classes' => [YourClass::class]) or switch to array/JSON serialization.int $currentSize with Atomic $currentSize. No action required, but if you had custom pool extensions, review them for similar non‑atomic counters. Monitor pool exhaustion under load; atomic operations are faster but pool size still needs tuning.swoole_error_log or Laravel’s file logging. For coroutine tracing, enable swoole.enable_coroutine in php.ini and use Swoole\Coroutine::getCid() in logs. Avoid dd()/dump() inside coroutines – they may hang.php --ri swoole). PHP 8.2–8.4 and Symfony 7/8 are supported; verify your Laravel version’s Symfony dependency matches (Laravel 11+ uses Symfony 7).HttpServerManager for custom request/response handling. Implement the Swoole cache interface for custom backends. Subclass ConnectionPool for other databases (e.g., MySQL) following the atomic‑size pattern.How can I help you explore Laravel packages today?