spiral/roadrunner-worker
PHP worker library for running apps on RoadRunner with the Spiral ecosystem. Provides a Worker API to handle incoming requests/jobs and communicate with the RoadRunner server, enabling high-performance, long-running PHP processes for HTTP and background tasks.
composer require spiral/roadrunner-workerSpiral\RoadRunner\Worker and implementing a request loop:
use Spiral\RoadRunner\Worker;
require __DIR__ . '/vendor/autoload.php';
$worker = new Worker();
while ($req = $worker->waitRequest()) {
try {
$payload = json_decode($req->getPayload(), true);
$response = ['result' => 'Handled: ' . ($payload['action'] ?? 'unknown')];
$worker->respond($response);
} catch (\Throwable $e) {
$worker->error((string)$e);
}
}
.rr.yaml to point to your worker script (exec: php worker.php)./rr serveQueueWorker, HttpWorker) by checking request headers (e.g., rr-worker-type) or payload structure$container = buildContainer(); // expensive setup once
while ($req = $worker->waitRequest()) {
$handler = $container->get(SomeHandler::class);
$handler->handle($req);
}
Spiral\RoadRunner\PSR7Client) and pass to Symfony Messenger or Laravel Queue for unified processing$worker->isStopRequested() in the loop to respond to RoadRunner’s /stop signal and flush pending work before exitingrespond() for observabilitytry/catch and use $worker->error($msg) for non-fatal issuesPsr\Http\Message\ServerRequestInterface (via spiral/roadrunner-http) or raw strings (via spiral/roadrunner-queue). Decode appropriately using $req->getPayload() or cast to PSR if availableRR_DEBUG=1 and check RoadRunner logs (./rrserve -d) to see worker communicationSpiral\RoadRunner\Environment to externalize config; override Worker methods like respond() for custom serialization (e.g., JSON to MessagePack)spiral/roadrunner-worker v3+ requires RoadRunner v2. Ensure Spiral\RoadRunner\Version::VERSION matches RoadRunner binary version at runtime—use RR_VERSION env for validationHow can I help you explore Laravel packages today?