limingxinleo/x-swoole-rpc

Rpc library for swoole

1.2.1 2018-05-24 02:20 UTC

This package is auto-updated.

Last update: 2024-10-17 19:21:28 UTC


README

Build Status

Go版本

安装

composer require limingxinleo/x-swoole-rpc

使用

服务端示例代码

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

use Xin\Swoole\Rpc\Server;

use Xin\Swoole\Rpc\Handler\Handler;

class TestHandler extends Handler
{
    public function test()
    {
        return 'success';
    }
}

$server = new Server();
$server->setHandler('test', TestHandler::class)->serve('0.0.0.0', '11520', [
    'pid_file' => './socket.pid',
    'daemonize' => false,
    'max_request' => 500, // 每个worker进程最大处理请求次数
    'open_eof_check' => true,
    'package_eof' => "\r\n",
]);

客户端示例代码

<?php

use Xin\Swoole\Rpc\Client\Client;

/**
 * Class TestClient
 * @method test
 */
class TestClient extends Client
{
    protected $service = 'test';

    protected $host = '127.0.0.1';

    protected $port = 11520;
}

$result = TestClient::getInstance()->test();