PHP code example of skoniks / php_cent
1. Go to this page and download the library: Download skoniks/php_cent 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/ */
skoniks / php_cent example snippets
'aliases' => [
...
'Centrifugo'=> SKONIKS\Centrifugo\Centrifugo::class,
]
...
'redis' => [
...
'centrifugo' => [
'host' => '127.0.0.1',
'password' => '',
'port' => 6379,
'database' => 1,
],
],
...
use Centrifugo;
class Controller {
public function _function(){
// declare Centrifugo
$centrifugo = new Centrifugo();
// generating token example
$current_time = time();
$user_id = '1234567890';
$token = Centrifugo::token($user_id, $current_time, 'custom info');
// publishing example
$centrifugo->publish("channel" , ["custom data"]);
// list of awailible methods:
$response = $centrifugo->publish($channel, $data);
$response = $centrifugo->unsubscribe($channel, $user_id);
$response = $centrifugo->disconnect($user_id);
$response = $centrifugo->presence($channel);
$response = $centrifugo->history($channel);
$response = $centrifugo->channels();
$response = $centrifugo->stats();
$response = $centrifugo->node();
$token = Centrifugo::token($user_id, $timestamp, $info);
// $response == false | when error
}