deepstreamhub/deepstream.io-client-php

此包已被废弃,不再维护。未建议替代包。

deepstreamHub的PHP客户端

v1.0.1 2017-07-03 08:56 UTC

This package is not auto-updated.

Last update: 2021-04-17 09:52:23 UTC


README

此库不再由deepstream核心团队维护。正在寻找可以转交维护权的维护者,或者添加贡献者权限。

deepstream.io-client-php

使用dsh HTTP API的PHP客户端

安装与运行测试

运行测试比较复杂,因为它需要一个两节点的deepstream集群,包括一个WebSocket deepstream(带有测试提供程序,该程序回答RPC并监听事件)和一个HTTP deepstream(实际测试运行于此)

Diagram

  • 安装PHP - 您可以从例如 http://windows.php.net/download/ 为windows获取
  • 将包含可执行文件(例如php.exe、php-cli.exe)的文件夹添加到您的路径中
  • https://phpunit.de/ 下载PHP Unit
  • phpunit-6.2.1.phar 文件移动到您的 deepstream.io-client-php 文件夹
  • 通过以下方式使其可执行
chmod +x phpunit.phar
  • 下载本地版本的Redis并在默认端口上运行它
  • 下载最新版本的deepstream并将其解压
  • 在其lib目录中运行 git clone git@github.com:deepstreamIO/dsx-connection-http.git
  • 通过 yarn install 安装插件
  • ds-conf 中的配置复制到您的deepstream的conf目录
  • 使用 ./deepstream.exe install msg redis 安装redis msg连接器
  • 使用以下命令启动两个deepstream实例
./deepstream.exe start -c conf/config-http.yml

./deepstream.exe start -c conf/config-ws.yml
  • deepstream.io-client-php 中安装测试提供程序
cd test-provider
yarn install
  • 运行测试提供程序
node test-provider.js
  • 使用以下命令运行测试
php phpunit-6.2.1.phar --bootstrap src\DeepstreamClient.php test\client-test.php

如果一切顺利,它看起来像这样 Screenshot

API

new DeepstreamClient( $url, $authData )

创建deepstream客户端

$client = new DeepstreamClient( 'https://api.deepstreamhub.com/api/v1', array(
    'token' => 'xxxx-xxxx-xxxx-xxxx'
))

setRecord( $recordName, [$path], $data )

将完整或部分数据写入记录

    # Writing full data
    $client->setRecord( 'user/johndoe', array(
        'firstname' => 'John',
        'lastname' => 'Doe',
        'age' => 32,
        'pets' => array( 'hamster', 'cat' )
    ));

    # Writing partial data
    $client->setRecord( 'user/johndoe', 'age', '33' );

$client->getRecord( $recordName )

读取给定记录的数据

    $firstname = $client->getRecord( 'user/johndoe' )->firstname;

$client->deleteRecord( $recordName )

删除记录

    $client->deleteRecord( 'user/johndoe' );

$client->getRecordVersion( $recordName )

检索记录的当前版本

    $version = $client->getRecordVersion( 'user/johndoe' );

$client->makeRpc( $rpcName, [$data] )

执行远程过程调用

    #with data
    $twentyfour = $client->makeRpc( 'multiply-by-two', 12 );

    #without data
    $client->makeRpc( 'logout' );

$client->emitEvent( $eventName, [$data] )

触发事件

    #with data
    $client->emitEvent( 'new-message', 'hey, what\'s up?' );

    #without data
    $client->emitEvent( 'ping' );

$client->startBatch()

开始一组批处理操作,这些操作将作为一个单独的请求执行

$client->executeBatch()

执行现有的一组批处理操作

    $client->startBatch()
    $client->emitEvent( 'new-message', 'hey, what\'s up?' );
    $client->getRecord( 'user/johndoe' );
    $client->setRecord( 'user/mike', 'age', 12 );
    $client->executeBatch();