zyzo/meteor-ddp-php

PHP 的 DDP 客户端

1.2.0 2016-09-09 22:59 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:17:56 UTC


README

A minimalist PHP library that implements DDP client, the realtime protocol for Meteor framework.

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

使用方法

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

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

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

use zyzo\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

更多用例可以在 examples 文件夹中找到。

安装方法

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

"require" : {
    "zyzo/meteor-ddp-php": "1.2.0"
}

并更新 composer 以自动检索此包

php composer.phar update

运行测试

cd tests
// install composer.phar in this folder
php composer.phar update
php [filename].php