mmplayer/jsonrpc

为 Yii2 应用程序提供的简单 JSON-RPC 客户端和服务器

dev-master 2015-06-08 18:15 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:54:30 UTC


README

使用 Yii2 的指南

PHP JSON-RPC

PHP JSON-RPC 是一个简单的 JSON-RPC 客户端和服务器。它目前处于 alpha 版本,预计很快将有一个稳定版本。提醒一下,API 也可能很快会发生变化 :)

Build Status

安装

Composer

如果您使用 Composer 来管理项目的依赖项,请将 trifs/phpjsonrpc 添加到项目的 composer.json 文件中。以下是一个最小的 composer.json 示例

{
    "require": {
        "trifs/jsonrpc": "dev-master"
    }
}

要使用 Composer 进行全局安装,可以运行

composer global require 'trifs/phpjsonrpc=*'

使用示例

客户端(单个请求)

$client = new trifs\jsonrpc\Client('http://example.com');
$client->request('method-one')
    ->send();

$client = new trifs\jsonrpc\Client('http://example.com');
$client->notification('method-one')
    ->send();

客户端(批量请求)

$client = new trifs\jsonrpc\Client('http://example.com');
$client->request('method-one')
    ->request('method-two')
    ->notification('method-three')
    ->send();

服务器

$input   = file_get_contents('php://input');
$invoker = function($method, array $params = []) {
    return time();
};

$server = new trifs\jsonrpc\Server($input, $invoker);
$server->run();

贡献

我们总是欢迎贡献。通过 GitHub pull requests 向我们发送您的贡献,您可以让我们的生活变得更轻松。

由于时间限制,我们不一定能像我们希望的那样快速响应。请不要将延迟视为个人问题,如果您觉得我们忘记回复,请随时在此提醒我们。

在开发环境中使用 PHP JSON-RPC

为了在本地设置 PHP JSON-RPC,请确保已安装 VagrantVirtualBox

git clone git://github.com/3fs/php-json-rpc
cd php-json-rpc
vagrant up

在做出更改后,运行 ./build/qa.sh all,坐下来放松。如果有报告问题,请重复。如果没有问题,请再试一次 :)