2017 © Pedro Peláez
 

library phpcent

Php library to communicate with Centrifugo/Centrifuge)

image

sl4mmer/phpcent

Php library to communicate with Centrifugo/Centrifuge)

  • Thursday, February 2, 2017
  • by sl4mmer
  • Repository
  • 4 Watchers
  • 36 Stars
  • 45,676 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 12 Forks
  • 3 Open issues
  • 5 Versions
  • 16 % Grown

The README.md

phpcent

Build Status Latest Version, (*1)

PHP library to communicate with Centrifugo v5 HTTP API (for Centrifugo v4 use phpcent v5.x, for Centrifugo v3 use phpcent v4.x)., (*2)

Library is published on the Composer: https://packagist.org/packages/centrifugal/phpcent, (*3)

composer require centrifugal/phpcent:~6.0

See Centrifugo server API documentation., (*4)

Basic Usage:, (*5)

$client = new \phpcent\Client("http://localhost:8000/api");
$client->setApiKey("Centrifugo API key");
$client->publish("channel", ["message" => "Hello World"]);

You can use phpcent to create connection token (JWT):, (*6)

$token = $client->setSecret("Centrifugo secret key")->generateConnectionToken($userId);

Connection token that will be valid for 5 minutes:, (*7)

$token = $client->setSecret("Centrifugo secret key")->generateConnectionToken($userId, time() + 5*60);

It's also possible to generate channel subscription token:, (*8)

$token = $client->setSecret("Centrifugo secret key")->generateSubscriptionToken($userId, $channel);

It's also possible to generate channel subscription token with expiration time, for example token for 30 mins:, (*9)

$token = $client->setSecret("Centrifugo secret key")->generateSubscriptionToken($userId, $channel, time() + 30*60);

Also API key and secret can be set in constructor:, (*10)

$client = new \phpcent\Client("http://localhost:8000/api", "<API key>", "<secret key>");

Timeouts:, (*11)

$client->setConnectTimeoutOption(0); // Seconds | 0 = never
$client->setTimeoutOption(2); // Seconds

All available API methods:, (*12)

$response = $client->publish($channel, $data);
$response = $client->broadcast($channels, $data);
$response = $client->unsubscribe($channel, $userId);
$response = $client->disconnect($userId);
$response = $client->presence($channel);
$response = $client->presenceStats($channel);
$response = $client->history($channel);
$response = $client->historyRemove($channel);
$response = $client->channels();
$response = $client->info();

To use assoc option while decoding JSON in response:, (*13)

$client->setUseAssoc(true);

SSL

In case if your Centrifugo server has invalid SSL certificate, you can use:, (*14)

$client->setSafety(false);

You can also use self signed certificate in safe manner:, (*15)

$client = new \phpcent\Client("https://localhost:8000/api");
$client->setCert("/path/to/certificate.pem");
$client->setCAPath("/ca/path"); // if you need.

Note: Certificate must match with host name in Client address (localhost in example above)., (*16)

DNS Resolution

This error may indicate your system is having trouble resolving IPv6 addresses:, (*17)

cURL error: Resolving timed out after [value] milliseconds

By default, both IPv4 and IPv6 addresses will attempt to be resolved. You can force it to only resolve IPv4 addresses with:, (*18)

$client->forceIpResolveV4();

Testing

Requirements:, (*19)

The provided PHPUnit tests assume that a local Centrifugo server is running and available at port 8000. This can be accomplished using Docker and the official Centrifugo image., (*20)

# Install package dependencies.
$ composer install

# The following command starts a Centrifugo server running in a background Docker container.
$ docker run -d -p 8000:8000 --name centrifugo centrifugo/centrifugo centrifugo --api_insecure

# Run the test suite.
$ vendor/bin/phpunit

# Shut down the Centrifugo container.
$ docker stop centrifugo

Authors

The Versions

02/02 2017

dev-master

9999999-dev https://github.com/centrifugal/phpcent

Php library to communicate with Centrifugo/Centrifuge)

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

centrifugo

29/02 2016

1.0.4

1.0.4.0 https://github.com/centrifugal/phpcent

Php library to communicate with Centrifugo/Centrifuge)

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

centrifugo

28/02 2016

1.0.3

1.0.3.0 https://github.com/centrifugal/phpcent

Php library to communicate with Centrifugo/Centrifuge)

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

centrifugo

07/07 2015

0.6.1

0.6.1.0 https://github.com/sl4mmer/phpcent

Php library to communicate with Centrifuge

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

centrifuge

15/06 2015

0.5.0

0.5.0.0 https://github.com/sl4mmer/phpcent

Php library to communicate with Centrifuge

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-curl *

 

centrifuge