PHP API Calls for the
// new Pubnub(pub_key, sub_key) $pubnub = new Pubnub( 'publish_key', 'subscribe_key' );
Get Your API Keys You need the Publish and Subscribe Keys. Ignore the Secret Key.
// pubnub->publish( options ) $pubnub->publish(array( 'channel' => 'my_channel', 'message' => array( 'my_var' => 'my text data' ) ));
// $pubnub->subscribe( options )
$pubnub->subscribe(array(
'channel ' => 'my_channel',
'callback' => function($message) {
var_dump($message['my_var']); // print message
return true; // keep listening?
}
));
Subscribe() function will *Block* as it waits for a new messages to be published.
// $pubnub->history( options ) $messages = $pubnub->history(array( 'channel' => 'my_channel', 'limit' => 10 ));
Nothing more complex is needed for real time message passing! For an in depth walk-through of the PHP Push API Framework, follow the Blog PHP Push API Walkthrough .