Laravel Octane on PAM
If your application already uses Laravel Octane, or you want Octane-only
features such as Octane::concurrently(), Octane tables, or ticks, you can keep
Octane and use PAM as its server. The pushinbr/pam-octane bridge adapts PAM’s
requests and responses to Octane’s own Worker, so Octane’s application
factory, sandbox, lifecycle events, and listeners all keep working.
You do not need Octane to run Laravel on PAM. Choose:
| Use | When |
|---|---|
pam start pam.php |
New projects, or you do not depend on Octane APIs |
pam octane:start |
You use Octane features, events, or config/octane.php already |
Installation
Section titled “Installation”pam composer require laravel/octane pushinbr/pam-octanepam artisan octane:install --server=pamoctane:install publishes config/octane.php and sets OCTANE_SERVER=pam in
.env.
Running the Server
Section titled “Running the Server”pam octane:start --port=8000 --workers=4Started octane-example-app-81917c92 (PID 1088806, 4 workers)pam octane:start runs a detached application under PAM’s process manager.
Each project gets its own managed name; pass --name= to choose one.
pam octane:statuspam octane:reload # zero-downtime: new workers boot before old ones drainpam octane:stoppam octane:start --watch # foreground, restarts on file changesOctane’s standard commands also work and pick pam from OCTANE_SERVER:
pam artisan octane:startpam artisan octane:reloadpam artisan octane:statuspam artisan octane:stopOctane’s usual options (--host, --port, --workers, --max-requests,
--watch) are accepted.
Production
Section titled “Production”For a foreground cluster under systemd or a container, run Artisan as the worker entrypoint:
pam start artisan \ --workers 8 \ --max-requests 100000 \ --admin-address 127.0.0.1:3010 \ -- pam:octane --host=127.0.0.1 --port=8000PAM then provides crash recovery, the admin endpoints, worker recycling, and
SIGHUP reloads, exactly as for pam.php.
Configuration
Section titled “Configuration”Publish the bridge’s configuration only if you need to change limits:
pam artisan vendor:publish --tag=pam-octane-configPAM_HOST=127.0.0.1PAM_PORT=8000PAM_REQUEST_TIMEOUT_MS=30000 # default: octane.max_execution_timePAM_MAX_BODY_BYTES=2097152PAM_MAX_RESPONSE_BYTES=268435456Set PAM_TLS_CERT and PAM_TLS_KEY to PEM files to terminate HTTPS (with
HTTP/2 and HTTP/3) in PAM.
Tables, Cache, Tasks, and Ticks
Section titled “Tables, Cache, Tasks, and Ticks”Features that only work on Swoole in stock Octane also work on PAM:
| Feature | On PAM |
|---|---|
Octane tables (octane.tables) |
Shared memory, one copy for all workers |
octane cache store |
Shared table sized by octane.cache |
Octane::concurrently() and tasks |
Runs on task workers started with --task-workers |
Octane::tick() |
One tick per second delivered to a task worker |
pam octane:start --workers=8 --task-workers=2use App\Models\Order;use App\Models\User;use Laravel\Octane\Facades\Octane;use Pam\Octane\PamOctane;
[$users, $orders] = Octane::concurrently([ fn () => User::count(), fn () => Order::count(),]);
PamOctane::table('votes')->incr('alice', 'count');Use PamOctane::table() instead of Octane::table(): released Octane versions
declare a Swoole\Table return type. Without --task-workers,
concurrently() runs the tasks one after another.
Edge Page Cache
Section titled “Edge Page Cache”The bridge adds a middleware and purge API on top of PAM’s edge cache:
PAM_RESPONSE_CACHE=trueuse Pam\Octane\Http\Middleware\CacheResponse;
Route::get('/products/{product}', ShowProduct::class) ->middleware(CacheResponse::for(ttl: 600, staleWhileRevalidate: 60, tags: ['products', 'product:{product}'])) ->withoutMiddleware(CacheResponse::STATEFUL);Purge when data changes:
use Pam\Octane\Facades\Pam;
Pam::purge('products', 'product:42');Pam::purgeUrl('/products/*');Pam::purgeAll();or add the Pam\Octane\Cache\PurgesPageCache trait to a model so it purges its
own tags after the transaction commits. Requests carrying Cookie or
Authorization always bypass the cache unless you set
PAM_RESPONSE_CACHE_ALLOW_COOKIES=true; only do that when every cached route
renders the same page for everyone.
Fork After Boot
Section titled “Fork After Boot”On Linux, pam octane:start boots Laravel once in a zygote and forks workers
from it: new, recycled, and replacement workers are ready in milliseconds and
share boot memory copy-on-write. The bridge closes database and Redis
connections before the fork. Set PAM_PREFORK_BOOT=engine to boot Laravel in
every worker instead.
Compatibility
Section titled “Compatibility”| PHP | Laravel | Octane |
|---|---|---|
| 8.5 (default) or 8.4 | 12.x, 13.x | 2.19 or newer |
php artisan pam:octane under the system PHP CLI reports an error: the server
needs PAM’s runtime. Use pam artisan or pam octane:start.