laravel/octane
Laravel Octane supercharges Laravel by keeping your app in memory and serving requests via high-performance servers like FrankenPHP, RoadRunner, Swoole, and Open Swoole. Boot once, handle many requests fast for lower latency and higher throughput.
Installation:
composer require laravel/octane
php artisan octane:install
Choose your preferred server (FrankenPHP, Swoole, RoadRunner, or Open Swoole) during installation.
First Use Case: Start Octane with:
php artisan octane:start
Your Laravel app now runs as a high-performance server. Access it via http://localhost:8000 (default port).
Key Files to Review:
octane.php (config file in config/).octane/ directory (generated server configs)artisan commands (octane:start, octane:stop, octane:install)Development Workflow:
php artisan octane:start for local development.php artisan octane:logs.Server-Side Patterns:
Octane::concurrently() for parallel tasks:
Octane::concurrently([
fn() => Task::dispatch(new ProcessPodcast()),
fn() => Task::dispatch(new SendEmail()),
]);
event:dispatch in routes or services:
event(new OrderShipped($order));
Integration with Laravel Features:
Cache::remember() or Cache::tags() as usual; Octane optimizes cache operations.Configuration:
config/octane.php:
'servers' => [
'frankenphp' => [
'workers' => 4,
'max_requests' => 1000,
'options' => [
'php' => [
'opcache.enable' => '1',
'opcache.validate_timestamps' => '0',
],
],
],
],
OCTANE_WORKERS=8).Deployment:
php artisan octane:install to generate server-specific configs (e.g., Caddyfile for FrankenPHP).Debugging:
php artisan octane:logs for server errors. FrankenPHP logs may appear in .octane/frankenphp/logs/.dd() or dump() in high-traffic routes; use Octane::debug() for safe debugging:
Octane::debug($variable);
opcache.validate_timestamps=0 in php.ini or Octane config to avoid file-watching overhead.Configuration Quirks:
OCTANE_WORKERS based on CPU cores (e.g., OCTANE_WORKERS=$(nproc)).memory_limit in php.ini or server config.'frankenphp' => [
'serve_static_files' => false,
],
Extension Points:
Octane\Server to support additional servers (e.g., Octane\Servers\CustomServer).app/Http/Kernel.php:
protected $middleware = [
\App\Http\Middleware\CustomMiddleware::class,
];
EventServiceProvider as usual; Octane optimizes their execution.Performance Tips:
php artisan route:cache
pgsql:pool or mysql:pool in .env) to reduce connection overhead.Debugging Tools:
http://localhost:2302). Access via:
'frankenphp' => [
'admin_host' => '0.0.0.0',
'admin_port' => 2302,
],
Octane\Metrics to track request times or memory usage:
Octane::metrics()->record('custom_metric', 100);
Migration Tips:
php-fpm pools with Octane workers. Update Nginx/Apache configs to proxy to Octane’s port (default: 8000).Edge Cases:
node_modules, vendor, or storage/logs from file watching in .octane/watch.json:
{
"ignore": ["node_modules", "vendor", "storage/logs"]
}
'frankenphp' => [
'http2' => false,
],
OCTANE_SKIP_INSTALL=true to skip installation in CI:
OCTANE_SKIP_INSTALL=true php artisan octane:start
```markdown
### Debugging Workflows
1. **Worker Crashes**:
- Check `.octane/workers/*.log` for worker-specific errors.
- Restart workers gracefully:
```bash
php artisan octane:restart
```
2. **Slow Requests**:
- Profile with Xdebug or Blackfire. Octane supports both:
```bash
OCTANE_XDEBUG=true php artisan octane:start
```
- Use `Octane::debug()` to log slow operations:
```php
$start = microtime(true);
// ... code ...
Octane::debug("Operation took " . (microtime(true) - $start) . "s");
```
3. **Configuration Conflicts**:
- Validate configs with:
```bash
php artisan octane:validate
```
- Reset configs to defaults:
```bash
php artisan octane:install --force
```
4. **Environment-Specific Issues**:
- Use `.env.octane` for Octane-specific overrides:
```
OCTANE_WORKERS=2
OCTANE_MAX_REQUESTS=500
```
- Test locally with Docker:
```bash
docker run --rm -p 8000:8000 -v $(pwd):/app laravel/octane:latest
```
How can I help you explore Laravel packages today?