ui
Composable, accessible components with thoughtful defaults. Build your own component library with code you can customize, extend, and make your own.
- 129k
- TypeScript
- MIT
- 21 h ago
Laravel Octane with Swoole Coroutine Support
Repo ModelsLab/octane-coroutine, read from GitHub 1 min ago. ModelsLab has not joined Take My Repo.
ModelsLab/octane-coroutine is a public repo on GitHub by ModelsLab. Laravel Octane with Swoole Coroutine Support. It declares the MIT license on GitHub. It is written mainly in PHP, has 10 stars and last changed on 2026-10-18. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-21.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
โก High-performance Laravel with true coroutine support for massive concurrency
Requires the latest Swoole with coroutine hooks enabled. Older versions are not supported.
This is an enhanced fork of Laravel Octane that adds true Swoole coroutine support, enabling your Laravel application to handle thousands of concurrent requests efficiently through non-blocking I/O.
Standard Octane uses a "One Worker = One Request" model. When a request performs blocking I/O (database queries, API calls, file operations), the entire worker is blocked:
8 workers ร 1 request per worker = 8 concurrent requests max
With 1-second blocking operations, this means only ~8 requests/second throughput.
This fork enables Swoole's coroutine runtime hooks (SWOOLE_HOOK_ALL), which automatically converts PHP's blocking functions into non-blocking, coroutine-safe versions:
32 workers ร ~87 concurrent requests per worker = 2,784+ concurrent requests
With the same 1-second blocking operations, this achieves 2,773+ requests/second โ a 360ร improvement!
sleep() โ Non-blocking coroutine sleepfile_get_contents() โ Non-blocking file I/Ocurl_exec() โ Non-blocking HTTP requestsswoole PHP extensionInstall via Composer from Packagist:
composer require modelslab/octane-coroutine
Then install Octane with Swoole:
php artisan octane:install swoole
# Install latest stable composer require modelslab/octane-coroutine:^0.8.7 # Install development version composer require modelslab/octane-coroutine:dev-main
# Update to the latest version composer update modelslab/octane-coroutine # Clear caches after updating php artisan config:clear php artisan cache:clear php artisan octane:reload
Tip: Pin your production deployments to specific versions:
{
"require": {
"modelslab/octane-coroutine": "^0.8.7"
}
}The package works out-of-the-box with sensible defaults. Coroutines are enabled by default with runtime hooks.
Start with appropriate worker count:
# Development (auto-detect CPU cores) php artisan octane:start --server=swoole # Production (explicit worker count) php artisan octane:start --server=swoole --workers=32
Edit config/octane.php if needed:
'swoole' => [ 'options' => [ 'enable_coroutine' => true, // Already enabled by default 'worker_num' => 32, 'max_request' => 10000, 'max_request_grace' => 1000, ], ],
Coroutine mode relies on coroutine-safe IO drivers and connection handling. Recommended defaults:
# Redis REDIS_CLIENT=phpredis # Database (disable PDO persistent connections in coroutine mode) DB_PERSISTENT=false # Database pool cleanup. Keep these enabled in production so burst-created # idle sockets are pruned instead of retained until worker shutdown. DB_POOL_HEARTBEAT=10 DB_POOL_MAX_IDLE_TIME=60 # Pooled connections are recycled after this many seconds (default 300, # 0 disables). PDO statements destroyed while a pooled connection is busy in # another coroutine leak server-side (mysqlnd skips COM_STMT_CLOSE and never # retries), so recycling bounds what any one connection can accumulate. # Set via the 'max_lifetime' key of the connection's 'pool' config array. # # The Worker also collects each request's cycle garbage BEFORE its pooled # connections re-enter the pool, which prevents the leak for statements the # request left behind. Garbage abandoned by one coroutine can still be # collected while another coroutine's connection is busy โ rare, and # max_lifetime recycling bounds that residue; it cannot be eliminated. # Redis persistent sockets are unsafe for request-scoped coroutine managers. REDIS_PERSISTENT=false REDIS_SESSION_PERSISTENT=false # Optional startup warning buffer for DB min_connections planning OCTANE_POOL_DB_MAX_CONNECTIONS_BUFFER=10
Notes:
composer require predis/predisREDIS_CLIENT=predisREDIS_PERSISTENT=falseworkers ร DB_POOL_MAX_CONNECTIONS, so size the pool below your database
server's max_connections budget.config/database.php is separate from the HTTP runtime.
The only octane.swoole.pool setting still used is the DB warning buffer above.Version v0.8.7 includes the production hardening used for high-concurrency
AI API workloads:
app()->handle() subrequests now resolve the coroutine-scoped HTTP
kernel/router and temporarily swap request bindings only inside the current
request scope. This prevents JSON/form/base64 API subrequests from corrupting
method, body, query, headers, or the outer request() helper.Regression coverage for this release includes concurrent request isolation, nested API shape preservation, request-time container binding isolation, locale/translator isolation, Redis manager isolation, dirty DB transaction cleanup, and DB idle pruning.
The v0.8.7 release was validated in Docker with host-network MySQL and Redis:
1883 passed, 2 skipped, 5446 assertions.82 tests, 687 assertions.7912/7912 PASS, zero leaks/errors.app()->handle() wrk: 15860/15860 PASS, zero leaks/errors.4049/4049 PASS, zero leaks/errors.15894 dirty opens followed by 15654
clean checks at transaction level 0, zero leaks/errors.458/458 PASS, zero leaks/errors.10k x 120s full-stack blocking IO: 10000/10000 valid JSON
200, zero leak responses.After stress, MySQL and Redis returned to baseline (Threads_connected=1,
connected_clients=1) with no container log stack traces.
This section clarifies the key concepts that make this fork different from standard Octane.
Workers are OS-level processes spawned by Swoole. Each worker:
--workers=N or worker_num in configStandard Octane: 1 Worker = 1 Request at a time (blocking)
Coroutines are lightweight, cooperative "threads" managed by Swoole at the application level (not OS-level). When a coroutine encounters blocking I/O, it yields control to other coroutines instead of blocking the entire worker.
Traditional: Worker blocks โ other requests wait
Coroutines: Worker yields โ other requests continue
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ SWOOLE SERVER โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Worker 0 Worker 1 โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Shared Laravel โ โ Shared Laravel โ โ
โ โ worker runtime โ โ worker runtime โ โ
โ โ โ โ โ โ
โ โ Coroutines: โ โ Coroutines: โ โ
โ โ cid:1 โ scope A โ โ cid:1 โ scope A โ โ
โ โ cid:2 โ scope B โ โ cid:2 โ scope B โ โ
โ โ cid:3 โ scope C โ โ cid:3 โ scope C โ โ
โ โ ... โ โ ... โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
This runtime does not use an HTTP application pool anymore. Each Swoole worker boots one shared Laravel worker runtime, and concurrent requests are isolated by the coroutine-aware container proxy plus per-request scoped state for bindings such as request, session, router, view, log, cache, and Redis managers.
The legacy octane.swoole.pool config namespace remains only for
db_max_connections_buffer, which is used by a startup safety warning.
Unit tests require a PHP build with the Swoole extension installed.
php83 vendor/bin/phpunit --testsuite Unit
The package is pool-free for HTTP workers. The relevant Swoole config looks like:
'swoole' => [ 'options' => [ 'worker_num' => 8, ], 'pool' => [ 'db_max_connections_buffer' => env('OCTANE_POOL_DB_MAX_CONNECTIONS_BUFFER', 10), ], ],
OCTANE_POOL_DB_MAX_CONNECTIONS_BUFFER only affects the startup warning that
checks MySQL max_connections against your configured database pool minimums.
Following Hyperf/Swoole best practices, this fork disables tick timers by default to prevent unnecessary CPU usage.
Octane can dispatch "tick" events to task workers every second. However:
'tick' => false in config/octane.php)In earlier configurations, tick timers with --task-workers=auto would create one task worker per CPU core (e.g., 12 workers on a 12-core system). Even with no traffic:
12 task workers ร tick every 1 second = constant CPU overhead
This causes high CPU usage even when the server is idle!
Only enable tick if you have listeners for TickReceived or TickTerminated events that need to run periodically:
// config/octane.php 'swoole' => [ 'tick' => true, // Enable tick timers ],
Then start with minimal task workers (not auto):
# Good: Only 1-2 task workers for tick php artisan octane:start --task-workers=1 # Bad: Creates CPU_COUNT task workers (excessive overhead) php artisan octane:start --task-workers=auto
| Scenario | Recommended --task-workers |
|---|---|
| Tick disabled (default) | 0 (auto) |
| Tick enabled | 1 or 2 |
| Heavy async task dispatch | 2 to 4 |
| Never use | auto (causes CPU overhead) |
Real-world load testing results with wrk:
wrk -t12 -c2000 -d30s http://localhost:8000/test
wrk -t12 -c20000 -d60s http://localhost:8000/test
| Configuration | Req/sec per worker | Concurrent requests per worker |
|---|---|---|
| Standard Octane | ~1 | 1 |
| With Coroutines | ~87 | ~87 |
Each worker can efficiently handle ~87 concurrent requests thanks to coroutines!
Enabled automatically on worker start:
// src/Swoole/Handlers/OnWorkerStart.php \Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL);
This converts all blocking I/O to coroutine-safe operations without any code changes required.
Workers log their initialization for monitoring:
๐ Worker #0 starting initialization...
โ
Worker #0 (PID: 4958) initialized and ready!
If a worker isn't ready, requests receive 503 responses until initialization completes:
{
"error": "Service Unavailable",
"message": "Worker not initialized yet",
"worker_id": 5
}Check worker initialization in your logs:
tail -f storage/logs/swoole_http.log | grep "Worker"
Monitor your application:
Memory needed โ workers ร 100-200MB per worker
Example: 32 workers = 3.2-6.4GB RAM
For high concurrency (10,000+ connections):
# Increase file descriptor limits ulimit -n 65536 # Add to /etc/security/limits.conf * soft nofile 65536 * hard nofile 65536
For extreme load:
// config/octane.php 'swoole' => [ 'options' => [ 'worker_num' => 64, 'backlog' => 65536, 'socket_buffer_size' => 2097152, ], ],
Enable debug logging to track worker behavior:
// Check worker initialization tail -f storage/logs/swoole_http.log // Monitor in real-time php artisan octane:start --server=swoole --workers=32 | grep "Worker"
max_connections can handle your concurrencyThis section provides specific, tested recommendations for achieving 10,000 requests/second on an 8-core CPU.
For 10K req/sec with 100ms average response time:
- Concurrent requests needed: 10,000 ร 0.1 = 1,000 concurrent
- With 8 workers, each needs: 1,000 รท 8 = 125 concurrent per worker
- There is no HTTP app pool cap; the real limits are memory, upstream capacity,
and whether your request path actually yields on blocking I/O.
// config/octane.php 'swoole' => [ 'options' => [ 'worker_num' => 8, // Match CPU cores 'max_request' => 10000, // Restart worker after N requests (memory safety) 'max_request_grace' => 1000, // Grace period for graceful restart 'backlog' => 8192, // Connection queue size 'socket_buffer_size' => 2097152, // 2MB socket buffer 'buffer_output_size' => 2097152, // 2MB output buffer ], ],
php artisan octane:start \
--server=swoole \
--workers=8 \
--task-workers=0 \
--max-requests=10000 \
--port=8000| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 8 cores | 8+ cores |
| RAM | 8GB | 16GB |
| File Descriptors | 65536 | 100000+ |
| Network | 1Gbps | 10Gbps |
Memory โ worker count ร base worker footprint + in-flight request state
Measure this under real load in your application. Pool-free coroutine mode is
dramatically lighter than pre-booting many application instances per worker, but
the exact number still depends on your middleware, services, and payload sizes.
Database pooling is separate from the HTTP runtime. Size it from worker count and your configured per-connection pool minimums and maximums.
// config/database.php 'mysql' => [ 'driver' => 'mysql', // ... other config 'pool' => [ 'min_connections' => 1, 'max_connections' => 50, 'connect_timeout' => 10.0, 'wait_timeout' => 3.0, ], ],
For example, 8 workers ร min_connections=1 means at least 8 DB connections
before real traffic. OCTANE_POOL_DB_MAX_CONNECTIONS_BUFFER only adjusts the
startup warning threshold for this planning.
Or configure MySQL server:
SET GLOBAL max_connections = 500; SET GLOBAL wait_timeout = 28800;
# /etc/sysctl.conf net.core.somaxconn = 65535 net.core.netdev_max_backlog = 65535 net.ipv4.tcp_max_syn_backlog = 65535 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 15 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 # Apply changes sysctl -p
# /etc/security/limits.conf * soft nofile 100000 * hard nofile 100000 * soft nproc 65535 * hard nproc 65535 # Apply (requires re-login) ulimit -n 100000
With the above configuration on 8-core CPU:
| Scenario | Expected req/sec |
|---|---|
| Simple JSON response | 15,000-20,000 |
| Database SELECT (cached) | 8,000-12,000 |
| Database SELECT (no cache) | 3,000-6,000 |
| External API call (100ms) | 8,000-10,000 |
| Complex business logic | 5,000-8,000 |
Contributions are welcome! Please read the contribution guide.
Please review our security policy to report vulnerabilities.
This fork maintains the original MIT license. See LICENSE.md.
Built with โค๏ธ by ModelsLab
Original Laravel Octane by Taylor Otwell and the Laravel team
ModelsLab/octane-coroutine is a public repo on GitHub by ModelsLab. Laravel Octane with Swoole Coroutine Support.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-10-18. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Composable, accessible components with thoughtful defaults. Build your own component library with code you can customize, extend, and make your own.
๐ Coroutine-based concurrency library for PHP
Laravel is a web application framework with expressive, elegant syntax. Weโve already laid the foundation for your next big idea โ freeing you to create without sweating the small things.
An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
ModelQ is a lightweight, battle-tested Python library for scheduling and queuing machine learning inference tasks. It's designed as a faster and simpler alternative to Celery for ML workloads, using Redis and threading to efficiently run background tasks.

This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/ModelsLab/octane-coroutineTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.