Skip to content

Artisan, Queues & Scheduler

HTTP traffic is served by pam start pam.php. Everything else your application runs (migrations, queue workers, the scheduler, Horizon, Nightwatch, custom daemons) is an Artisan command, and PAM runs Artisan with its embedded PHP through pam artisan.

Keep the two worlds separate: never consume a queue or run the scheduler inside an HTTP request. Each long-running role is its own process with its own restart, scaling, and memory policy.

Terminal window
pam artisan migrate --force
pam artisan route:list
pam artisan tinker
pam artisan about

pam artisan gives Artisan a real console identity:

  • app()->runningInConsole() is true and PHP_SAPI is cli, so packages register their commands and publishables;
  • arguments, standard input/output/error, and exit codes behave normally; and
  • PHP_BINARY is the pam binary. Laravel features that spawn PHP_BINARY artisan ... (the scheduler’s background tasks, Horizon’s supervisors) therefore start pam artisan ... automatically.

Queue workers run exactly as in any Laravel application:

Terminal window
pam artisan queue:work redis --sleep=1 --tries=3 --max-time=3600

A job dispatched from an HTTP request goes through the request’s sandboxed Bus dispatcher to the shared queue connection, and a worker picks it up:

app/Http/Controllers/InvoiceController.php
public function store(StoreInvoiceRequest $request): JsonResponse
{
$invoice = Invoice::create($request->validated());
SendInvoice::dispatch($invoice);
return response()->json($invoice, 201);
}
Terminal window
pam artisan queue:work --once --stop-when-empty
2026-12-02 18:50:09 App\Jobs\DemoJob .......... RUNNING
2026-12-02 18:50:09 App\Jobs\DemoJob .......... 3.69ms DONE

queue:work is itself a long-running PHP process, so the advice from Request Lifecycle applies here too. PAM’s request sandbox does not wrap queue jobs: follow Laravel’s own guidance for --max-jobs, --max-time, --memory, timeouts, and idempotent jobs.

Run the scheduler as one long-lived process:

Terminal window
pam artisan schedule:work

or from cron, once a minute:

crontab
* * * * * cd /srv/app/current && pam artisan schedule:run >> /dev/null 2>&1

Scheduled closures and commands run as usual:

routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('reports:daily')->dailyAt('02:00')->onOneServer();
Schedule::job(new PruneExports)->hourly();

Run exactly one scheduler per environment, or use onOneServer() with a shared cache store.

These packages ship their own long-running Artisan commands. Run each as a separate process:

Package Command Notes
Laravel Horizon pam artisan horizon Horizon spawns its supervisors with PHP_BINARY, which is pam. Horizon is exercised on Laravel 12 in PAM’s compatibility suite.
Laravel Reverb pam artisan reverb:start PAM’s suite covers Reverb provider discovery; validate the WebSocket server under your own load.
Laravel Nightwatch pam artisan nightwatch:agent pam artisan pam:nightwatch --install-process adds it to the manifest.

PAM also has its own WebSocket transport. Pass --socket to pam init to serve WebSockets on the same listener as HTTP.

pushinbr/pam-laravel can start, stop, and scale your long-running roles from one JSON file. pam artisan pam:install publishes this default:

pam.processes.json
{
"processes": {
"http": {
"command": ["pam", "start", "pam.php", "--workers", "2", "--admin-address", "127.0.0.1:3011"],
"instances": 1
},
"queue": {
"command": ["pam", "artisan", "queue:work", "--sleep=1", "--tries=3"],
"instances": 1
},
"scheduler": {
"command": ["pam", "artisan", "schedule:work"],
"instances": 1
}
}
}

Commands are arrays, not shell strings, so arguments cannot be injected. Process names must match ^[a-z][a-z0-9_-]*$; instances are clamped to 1..128.

Manage it with pam:process:

Terminal window
pam artisan pam:process up # start every stopped instance
pam artisan pam:process up queue # start one process
pam artisan pam:process status
pam artisan pam:process restart queue
pam artisan pam:process scale queue 4
pam artisan pam:process logs queue 1 # print queue-1.log
pam artisan pam:process stop
+-----------+----------+---------+---------+
| Process | Instance | PID | State |
+-----------+----------+---------+---------+
| http | 1 | 1055981 | running |
| queue | 1 | 1055983 | running |
| scheduler | 1 | 1055987 | running |
+-----------+----------+---------+---------+

How it works:

  • Each instance runs detached, with output appended to storage/logs/pam/<name>-<instance>.log.
  • PIDs are recorded in storage/pam/processes/<name>-<instance>.pid together with the process start time from /proc, so a recycled PID is never mistaken for your process (Linux only).
  • stop sends SIGTERM, waits up to PAM_PROCESS_STOP_TIMEOUT seconds (default 10), then sends SIGKILL.
  • scale stores overrides in storage/pam/processes/scale.json, then restarts that process with the new instance count.

When releases are read-only, every role must share the same writable storage:

Terminal window
export PAM_LARAVEL_STORAGE_PATH=/var/lib/pam
pam start pam.php --workers 4

PAM_LARAVEL_STORAGE_PATH is applied by pam.php. For Artisan processes, set Laravel’s storage path the same way your application does (for example, a symlinked storage directory in each release), so logs and cache files end up in one place.

Build Laravel’s caches in the release before starting any process:

Terminal window
pam artisan optimize # config, events, routes, views

Because workers boot once, a cached configuration is read once per worker generation. After you change .env or config, rebuild the cache and reload the workers (see zero-downtime reloads). Queue workers and the scheduler must be restarted too:

Terminal window
pam artisan queue:restart