PHP code example of sl4mmer / phpcent

1. Go to this page and download the library: Download sl4mmer/phpcent library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sl4mmer / phpcent example snippets


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

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

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

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

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

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

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

$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();

$client->setUseAssoc(true);

$client->setSafety(false);

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

$client->forceIpResolveV4();