This package will help you to manage Roadrunner services
Make sure that your server is configured with following PHP version and extensions:
- PHP 7.4+
You can install the package via composer:
composer require spiral/roadrunner-services
Such a configuration would be quite feasible to run:
version: '2.7'
rpc:
listen: tcp://127.0.0.1:6001
service: {}
Then you need to create an instance of Spiral\RoadRunner\Services\Manager
use Spiral\RoadRunner\Services\Manager;
use Spiral\Goridge\RPC\RPC;
$rpc = RPC::create('tcp://127.0.0.1:6001'));
// or
$rpc = RPC::fromGlobals();
// or
$rpc = RPC::fromEnvironment(new \Spiral\RoadRunner\Environment([
'RR_RPC' => 'tcp://127.0.0.1:6001'
]));
$manager = new Manager($rpc);
use Spiral\RoadRunner\Services\Exception\ServiceException;
try {
$result = $manager->create(
name: 'listen-jobs',
command: 'php app.php queue:listen',
processNum: 3,
execTimeout: 0,
remainAfterExit: false,
env: ['APP_ENV' => 'production'],
restartSec: 30
);
if (!$result) {
throw new ServiceException('Service creation failed.');
}
} catch (ServiceException $e) {
// handle exception
}
use Spiral\RoadRunner\Services\Exception\ServiceException;
try {
$status = $manager->status(name: 'listen-jobs');
// Will return an array with service status fields
// [
// 'cpu_percent' => 59.5,
// 'pid' => 33,
// 'memory_usage' => 200,
// 'command' => 'foo/bar',
// ]
} catch (ServiceException $e) {
// handle exception
}
use Spiral\RoadRunner\Services\Exception\ServiceException;
try {
$result = $manager->restart(name: 'listen-jobs');
if (!$result) {
throw new ServiceException('Service restart failed.');
}
} catch (ServiceException $e) {
// handle exception
}
use Spiral\RoadRunner\Services\Exception\ServiceException;
try {
$result = $manager->terminate(name: 'listen-jobs');
if (!$result) {
throw new ServiceException('Service termination failed.');
}
} catch (ServiceException $e) {
// handle exception
}
use Spiral\RoadRunner\Services\Exception\ServiceException;
try {
$services = $manager->list();
// Will return an array with services names
// ['listen-jobs', 'websocket-connection']
} catch (ServiceException $e) {
// handle exception
}