spiral/roadrunner-services 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spiral/roadrunner-services

最新稳定版本:2.2.1

Composer 安装命令:

composer require spiral/roadrunner-services

包简介

RoadRunner services manager

README 文档

README

Roadrunner services manager

PHP Version Require Latest Stable Version phpunit psalm Total Downloads

This package will help you to manage Roadrunner services

Requirements

Make sure that your server is configured with following PHP version and extensions:

  • PHP 8.1+

Installation

You can install the package via composer:

composer require spiral/roadrunner-services

Usage

Such a configuration would be quite feasible to run:

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'));
$manager = new Manager($rpc);

Create a new service

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
}

Check service status

use Spiral\RoadRunner\Services\Exception\ServiceException;

try {
    $status = $manager->statuses(name: 'listen-jobs');
    
    // Will return an array with statuses of every run process
    // [
    //    [
    //      'cpu_percent' => 59.5,
    //      'pid' => 33,
    //      'memory_usage' => 200,
    //      'command' => 'foo/bar',
    //      'error' => null
    //    ],
    //    [
    //      'cpu_percent' => 60.2,
    //      'pid' => 34,
    //      'memory_usage' => 189,
    //      'command' => 'foo/bar'
    //      'error' => [
    //          'code' => 1,
    //          'message' => 'Process exited with code 1'
    //          'details' => [...] // array with details
    //      ]
    //    ],
    // ] 
} catch (ServiceException $e) {
    // handle exception
}

Restart service

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
}

Terminate service

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
}

List of all services

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
}

统计信息

  • 总下载量: 63.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 5
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固