Skip to content

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
Terminal window
pam composer require laravel/octane pushinbr/pam-octane
pam artisan octane:install --server=pam

octane:install publishes config/octane.php and sets OCTANE_SERVER=pam in .env.

Terminal window
pam octane:start --port=8000 --workers=4
Started 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.

Terminal window
pam octane:status
pam octane:reload # zero-downtime: new workers boot before old ones drain
pam octane:stop
pam octane:start --watch # foreground, restarts on file changes

Octane’s standard commands also work and pick pam from OCTANE_SERVER:

Terminal window
pam artisan octane:start
pam artisan octane:reload
pam artisan octane:status
pam artisan octane:stop

Octane’s usual options (--host, --port, --workers, --max-requests, --watch) are accepted.

For a foreground cluster under systemd or a container, run Artisan as the worker entrypoint:

Terminal window
pam start artisan \
--workers 8 \
--max-requests 100000 \
--admin-address 127.0.0.1:3010 \
-- pam:octane --host=127.0.0.1 --port=8000

PAM then provides crash recovery, the admin endpoints, worker recycling, and SIGHUP reloads, exactly as for pam.php.

Publish the bridge’s configuration only if you need to change limits:

Terminal window
pam artisan vendor:publish --tag=pam-octane-config
PAM_HOST=127.0.0.1
PAM_PORT=8000
PAM_REQUEST_TIMEOUT_MS=30000 # default: octane.max_execution_time
PAM_MAX_BODY_BYTES=2097152
PAM_MAX_RESPONSE_BYTES=268435456

Set PAM_TLS_CERT and PAM_TLS_KEY to PEM files to terminate HTTPS (with HTTP/2 and HTTP/3) in PAM.

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
Terminal window
pam octane:start --workers=8 --task-workers=2
app/Http/Controllers/DashboardController.php
use 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.

The bridge adds a middleware and purge API on top of PAM’s edge cache:

PAM_RESPONSE_CACHE=true
routes/web.php
use 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.

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.

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.