gbksoft/phpcent

PHP 库,用于与 Centrifugo/Centrifuge 进行通信

1.0.5 2017-10-25 13:51 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:16:56 UTC


README

PHP 库,用于与 Centrifugo HTTP API 进行通信。

库已在 Composer 上发布:https://packagist.org.cn/packages/sl4mmer/phpcent

{
    "require": {
        "gbksoft/phpcent":"~1.0.5",
    }
}

完整 Centrifugo 文档

基本用法

        
        $client = new \phpcent\Client("https://:8000");
        $client->setSecret("secret key from Centrifugo");
        $client->publish("main_feed", ["message" => "Hello Everybody"]);
        $history = $client->history("main_feed");
        

您可以使用 phpcent 创建前端令牌

	$token = $client->setSecret($pSecret)->generateClientToken($user, $timestamp);

或创建私有频道签名

	$sign = $client->setSecret($pSecret)->generateClientToken($client, $channel);

从 1.0.3 版本开始,phpcent 具有广播实现。

$client->broadcast(['example:entities', 'example:moar'], ['user_id' => 2321321, 'state' => '1']);

SSL

如果您的 Centrifugo 服务器有无效的 SSL 证书,您可以使用

\phpcent\Transport::setSafety(\phpcent\Transport::UNSAFE);

从 1.0.5 版本开始,您可以安全地使用自签名证书

$client = new \phpcent\Client("https://:8000");
$client->setSecret("secret key from Centrifugo");
$transport = new \phpcent\Transport();
$transport->setCert("/path/to/certificate.pem");
$client->setTransport($transport);

注意:证书必须与 Client 地址中的主机名匹配(例如,上面的示例中为 localhost)。

其他客户端