This library is no longer being maintained by deepstream core. Looking for a maintainer we can transfer this to, or add contributor rights to.
PHP Client using the dsh HTTP API
Running the tests is a bit trickier as it requires a two-node deepstream cluster, consisting of a Websocket deepstream with a test-provider that answers RPCs and listens for events and a HTTP deepstream that the actual tests are run against:
- Install PHP - you can get it from e.g. http://windows.php.net/download/ for windows
- Add the folder with the executables (e.g. php.exe, php-cli.exe) to your path
- Download PHP Unit from https://phpunit.de/
- Move the
phpunit-6.2.1.phar
file to yourdeepstream.io-client-php
folder - Make it executable via
chmod +x phpunit.phar
- Download a local version of Redis and run it on its default port
- Download the latest deepstream version and unzip it
- run
git clone [email protected]:deepstreamIO/dsx-connection-http.git
in its lib directory - install the plugin via
yarn install
- copy the configs in
ds-conf
into your deepstream's conf directory - install the redis msg connector using
./deepstream.exe install msg redis
- start two deepstream instances with
./deepstream.exe start -c conf/config-http.yml
and
./deepstream.exe start -c conf/config-ws.yml
- install the test provider in the
deepstream.io-client-php
cd test-provider
yarn install
- run the test provider
node test-provider.js
- run the tests using
php phpunit-6.2.1.phar --bootstrap src\DeepstreamClient.php test\client-test.php
If it all works it looks like this
Creates the deepstream client
$client = new DeepstreamClient( 'https://api.deepstreamhub.com/api/v1', array(
'token' => 'xxxx-xxxx-xxxx-xxxx'
))
Writes full or partial data to a record
# 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' );
Reads the data for a given record
$firstname = $client->getRecord( 'user/johndoe' )->firstname;
Deletes a record
$client->deleteRecord( 'user/johndoe' );
Retrieves the current version of a record
$version = $client->getRecordVersion( 'user/johndoe' );
Executes a Remote Procedure Call
#with data
$twentyfour = $client->makeRpc( 'multiply-by-two', 12 );
#without data
$client->makeRpc( 'logout' );
Emits an event
#with data
$client->emitEvent( 'new-message', 'hey, what\'s up?' );
#without data
$client->emitEvent( 'ping' );
Starts a set of batch operations that will be executed as a single request
Executes an existing set of batch operations
$client->startBatch()
$client->emitEvent( 'new-message', 'hey, what\'s up?' );
$client->getRecord( 'user/johndoe' );
$client->setRecord( 'user/mike', 'age', 12 );
$client->executeBatch();