beekirr / centrifugal-php-client
用于与 Centrifugo/Centrifuge 通信的 PHP 库
1.0.4
2016-02-29 13:53 UTC
Requires
- php: >=5.3.0
- ext-curl: *
This package is not auto-updated.
Last update: 2024-09-26 18:42:51 UTC
README
用于与 Centrifugo HTTP API 通信的 PHP 库。
该库已发布在 Composer 上:https://packagist.org.cn/packages/sl4mmer/phpcent
{ "require": { "sl4mmer/phpcent":"dev-master", } }
基本用法
$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
)。
其他客户端
- php-centrifugo - 允许使用 Redis Engine API 队列。
- php_cent by skoniks