synchrotalk/meteor-ddp-php

PHP 的 DDP 客户端

dev-refactor 2016-09-20 20:57 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:09:34 UTC


README

这是一个简单的 PHP 库,实现了 Meteor 框架的实时协议 DDP 客户端。

Join the chat at https://gitter.im/synchrotalk/meteor-ddp-php

如何使用

假设你在 meteor 服务器代码中声明了一个远程函数 foo

Meteor.methods({
  foo : function (arg) {
    check(arg, Number);
    if (arg == 1) { return 42; }
    return "You suck";
  }
});

然后在你的 PHP 客户端代码中,你可以通过执行以下操作调用 foo

use synchrotalk\MeteorDDP\DDPClient;

$client = new DDPClient('localhost', 3000);

$client->connect();

$client->call("foo", array(1));
while(($a = $client->getResult("foo")) === null) {};

echo 'Result = ' . $a . PHP_EOL;

$client->stop();

===>

Result = 42

更多使用案例可以在 示例 文件夹中找到。

如何安装

此库可通过 composer(PHP 依赖管理器)获取。请在你的 composer.json 中添加以下内容

"require" : {
    "synchrotalk/meteor-ddp-php": "0.1.0"
}

并更新 composer 以自动检索此包

php composer.phar update

路线图

版本

0.1.0