承接 spiral/roadrunner-tcp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

spiral/roadrunner-tcp

Composer 安装命令:

composer require spiral/roadrunner-tcp

包简介

RoadRunner: TCP worker

README 文档

README

RoadRunner TCP Plugin

PHP Version Require Latest Stable Version phpunit psalm Codecov Total Downloads type-coverage psalm-level

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a service with the ability to extend its functionality on a per-project basis.

RoadRunner includes TCP server and can be used to replace classic TCP setup with much greater performance and flexibility.

Official Website | Documentation

This repository contains the codebase TCP PHP workers. Check spiral/roadrunner to get application server.

Installation

To install application server and TCP codebase:

composer require spiral/roadrunner-tcp

You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:

composer require spiral/roadrunner-cli --dev

To download latest version of application server:

vendor/bin/rr get

Usage

For example, such a configuration would be quite feasible to run:

tcp:
  servers:
    smtp:
      addr: tcp://127.0.0.1:1025
      delimiter: "\r\n" # by default
    server2:
      addr: tcp://127.0.0.1:8889

  pool:
    num_workers: 2
    max_jobs: 0
    allocate_timeout: 60s
    destroy_timeout: 60s

If you have more than 1 worker in your pool TCP server will send received packets to different workers, and if you need to collect data you have to use storage, that can be accessed by all workers, for example RoadRunner Key Value

Example

To init abstract RoadRunner worker:

<?php

require __DIR__ . '/vendor/autoload.php';

use Spiral\RoadRunner\Worker;
use Spiral\RoadRunner\Tcp\TcpWorker;
use Spiral\RoadRunner\Tcp\TcpResponse;
use Spiral\RoadRunner\Tcp\TcpEvent;

// Create new RoadRunner worker from global environment
$worker = Worker::create();

$tcpWorker = new TcpWorker($worker);

while ($request = $tcpWorker->waitRequest()) {

    try {
        if ($request->getEvent() === TcpEvent::Connected) {
            // You can close connection according your restrictions
            if ($request->getRemoteAddress() !== '127.0.0.1') {
                $tcpWorker->close();
                continue;
            }
            
            // -----------------
            
            // Or continue read data from server
            // By default, server closes connection if a worker doesn't send CONTINUE response 
            $tcpWorker->read();
            
            // -----------------
            
            // Or send response to the TCP connection, for example, to the SMTP client
            $tcpWorker->respond("220 mailamie \r\n");
            
        } elseif ($request->getEvent() === TcpEvent::Data) {
                   
            $body = $request->getBody();
            
            // ... handle request from TCP server [tcp_access_point_1]
            if ($request->getServer() === 'tcp_access_point_1') {

                // Send response and close connection
                $tcpWorker->respond('Access denied', TcpResponse::RespondClose);
               
            // ... handle request from TCP server [server2] 
            } elseif ($request->getServer() === 'server2') {
                
                // Send response to the TCP connection and wait for the next request
                $tcpWorker->respond(\json_encode([
                    'remote_addr' => $request->getRemoteAddress(),
                    'server' => $request->getServer(),
                    'uuid' => $request->getConnectionUuid(),
                    'body' => $request->getBody(),
                    'event' => $request->getEvent()
                ]));
            }
           
        // Handle closed connection event 
        } elseif ($request->getEvent() === TcpEvent::Close) {
            // Do something ...
            
            // You don't need to send response on closed connection
        }
        
    } catch (\Throwable $e) {
        $tcpWorker->respond("Something went wrong\r\n", TcpResponse::RespondClose);
        $worker->error((string)$e);
    }
}
try Spiral Framework

Testing:

This codebase is automatically tested via host repository - spiral/roadrunner.

License:

The MIT License (MIT). Please see LICENSE for more information. Maintained by Spiral Scout.

spiral/roadrunner-tcp 适用场景与选型建议

spiral/roadrunner-tcp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.03M 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 spiral/roadrunner-tcp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spiral/roadrunner-tcp 我们能提供哪些服务?
定制开发 / 二次开发

基于 spiral/roadrunner-tcp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-06