hetao29 / phpcent2
用于与Centrifugo v2.x通信的PHP库
2.0.1
2018-11-01 08:30 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- ext-json: *
- firebase/php-jwt: >=5.0.0
Requires (Dev)
- firebase/php-jwt: >=5.0.0
This package is auto-updated.
Last update: 2024-09-15 17:20:30 UTC
README
用于与Centrifugo HTTP API通信的PHP库。
该库已在Composer上发布: https://packagist.org.cn/packages/sl4mmer/phpcent
{ "require": { "hetao29/phpcent2":"dev-master", } }
基本用法
//to backend api $client = new \phpcent2\Client("https://:8000"); $client->setApikey("api key from Centrifugo");//to backend api $client->publish("main_feed", ["message" => "Hello Everybody"]); $history = $client->history("main_feed"); //to get token $client->setSecret("secret key from Centrifugo"); $token = $client->getToken([ "data"=>[], "sub"=>1 ]);
您可以使用 phpcent2
创建前端令牌
$token = $client->setSecret($pSecret)->getToken($data);
SSL
如果您的Centrifugo服务器具有无效的SSL证书,您可以使用
\phpcent2\Transport::setSafety(\phpcent\Transport::UNSAFE);
从1.0.5版本开始,您可以使用自签名证书以安全的方式
$client = new \phpcent2\Client("https://:8000"); $client->setSecret("secret key from Centrifugo"); $transport = new \phpcent2\Transport(); $transport->setCert("/path/to/certificate.pem"); $client->setTransport($transport);
注意: 证书必须与客户端地址中的主机名匹配(例如,上面的示例中的 localhost
)。
其他客户端
- php-centrifugo - 允许使用Redis Engine API队列。
- php_cent by skoniks