Exemplo n.º 1
0
<?php

## Capture Publish and Subscribe Keys from Command Line
$publish_key = isset($argv[1]) ? $argv[1] : false;
$subscribe_key = isset($argv[2]) ? $argv[2] : false;
# Print usage if missing info.
if (!($publish_key && $subscribe_key)) {
    echo "\n    ==============\n    EXAMPLE USAGE:\n    ==============\n    php ./publish-example.php PUBLISH-KEY SUBSCRIBE-KEY\n\n";
    exit;
}
## Require Pubnub API
echo "Loading Pubnub.php Class\n";
require '../Pubnub.php';
## -----------------------------------------
## Create Pubnub Client API (INITIALIZATION)
## -----------------------------------------
echo "Creating new Pubnub Client API\n";
$pubnub = new Pubnub($publish_key, $subscribe_key);
## Get History
echo "Requesting History...\n";
$messages = $pubnub->history(array('channel' => 'hello_world', 'limit' => 100));
var_dump($messages);
## Prints Published Messages.
?>

Exemplo n.º 2
0
$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
$secret_key = isset($argv[3]) ? $argv[3] : false;
$ssl_on = isset($argv[4]);
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $ssl_on);
## ---------------------------------------------------------------------------
## Generate Random Channel Name
## ---------------------------------------------------------------------------
$channel = 'unit-test-' . rand(0, 100000000) . rand(0, 100000000);
## ---------------------------------------------------------------------------
## Get History Part 1
## ---------------------------------------------------------------------------
$history = $pubnub->history(array('channel' => $channel, 'limit' => 1));
test(count($history), 0, 'Initial Empty History');
## ---------------------------------------------------------------------------
## PUBLISH
## ---------------------------------------------------------------------------
$pubish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Hi. (顶顅Ȓ)'));
test($pubish_success[0], 1, 'Publish First Message');
## ---------------------------------------------------------------------------
## Get History Part 2
## ---------------------------------------------------------------------------
$history = $pubnub->history(array('channel' => $channel, 'limit' => 1));
test(count($history), 1, 'History With 1 Item');
test($history[0], 'Hi. (顶顅Ȓ)', 'History Message Text == "Hi. (顶顅Ȓ)"');
## ---------------------------------------------------------------------------
## PUBLISH 2
## ---------------------------------------------------------------------------
// This should return a failure (0) JSON Array
$publish_success = $pubnub->publish(array('channel' => $channel, 'message' => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
echo $publish_success[0] . $publish_success[1];
echo "\r\n";
## ---------------------------------------------------------------------------
## detailedHistory Example
## ---------------------------------------------------------------------------
echo "Running detailedHistory\r\n";
$history = $pubnub->detailedHistory(array('channel' => $channel, 'count' => 5, 'end' => "13466530169226760"));
print_r($history);
echo "\r\n";
## ---------------------------------------------------------------------------
## History Example
## ---------------------------------------------------------------------------
echo "Running history\r\n";
$history = $pubnub->history(array('channel' => $channel, 'limit' => 2));
echo $history;
echo "\r\n";
## ---------------------------------------------------------------------------
## Here_Now Example
## ---------------------------------------------------------------------------
echo "Running here_now\r\n";
$here_now = $pubnub->here_now(array('channel' => $channel));
var_dump($here_now);
echo "\r\n";
## ---------------------------------------------------------------------------
## Timestamp Example
## ---------------------------------------------------------------------------
echo "Running timestamp\r\n";
$timestamp = $pubnub->time();
echo 'Timestamp: ' . $timestamp;