camcima / pubnub-php-api
dev-master
2016-11-04 15:06 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2022-02-01 12:22:15 UTC
README
###使用该 API 您必须拥有 PubNub 账户。###http://www.pubnub.com/account
PubNub 3.3 实时云推送 API - PHP
www.pubnub.com - PubNub 云实时推送服务。http://www.pubnub.com/blog/php-push-api-walkthrough
PubNub 是一个针对 Web 和移动游戏的巨大可扩展实时服务。
这是一个基于云的服务,用于广播实时消息。
同时向成千上万的 Web 和移动客户端广播。
PHP 推送 API
$pubnub = new Pubnub( "demo", ## PUBLISH_KEY "demo", ## SUBSCRIBE_KEY "", ## SECRET_KEY false ## SSL_ON? );
发送消息(发布)
$info = $pubnub->publish(array( 'channel' => 'hello_world', ## REQUIRED Channel to Send 'message' => 'Hey World!' ## REQUIRED Message String/Array )); print_r($info);
请求消息(历史记录,已弃用,请使用下面的 detailedHistory())
$messages = $pubnub->history(array( 'channel' => 'hello_world', ## REQUIRED Channel to Send 'limit' => 100 ## OPTIONAL Limit Number of Messages )); print_r($messages); ## Prints array of messages.
请求服务器时间(时间)
$timestamp = $pubnub->time(); var_dump($timestamp); ## Prints integer timestamp.
接收消息(订阅)PHP 5.2.0
$pubnub->subscribe(array( 'channel' => 'hello_world', ## REQUIRED Channel to Listen 'callback' => create_function( ## REQUIRED PHP 5.2.0 Method '$message', 'var_dump($message); return true;' ) ));
接收消息(订阅)PHP 5.3.0
$pubnub->subscribe(array( 'channel' => 'hello_world', ## REQUIRED Channel to Listen 'callback' => function($message) { ## REQUIRED Callback With Response var_dump($message); ## Print Message return true; ## Keep listening (return false to stop) } ));
实时加入/离开事件(存在)
$pubnub->presence(array( 'channel' => $channel, 'callback' => function($message) { print_r($message); echo "\r\n"; return true; } ));
按需占用状态(here_now)
$here_now = $pubnub->here_now(array( 'channel' => $channel ));
详细历史记录(detailedHistory())
$history = $pubnub->detailedHistory(array( 'channel' => $channel, 'count' => 10, 'end' => "13466530169226760" ));