<?php

require '../Pubnub.php';
$pubnub = new Pubnub('demo', 'demo');
$pubnub->publish(array('channel' => 'my_test_channel', 'message' => array('some_text' => 'hello!')));
Example #2
0
<?php

require_once 'Pubnub.php';
## ---------------------------------------------------------------------------
## USAGE:
## ---------------------------------------------------------------------------
## php ./bootstrap.php
## Capture Publish and Subscribe Keys from Command Line
$publish_key = isset($argv[7]) ? $argv[7] : 'demo';
$subscribe_key = isset($argv[8]) ? $argv[8] : 'demo';
$secret_key = isset($argv[9]) ? $argv[9] : false;
$cipher_key = isset($argv[10]) ? $argv[10] : false;
$ssl_on = false;
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on);
## ---------------------------------------------------------------------------
## Find all Streams running on this system
## ---------------------------------------------------------------------------
$channel = "stockblast";
$streams = system(implode(' | ', array('ps a', 'grep stock.php', 'grep -v grep', 'awk "{print \\$7}"', 'tr "\\n+" ","')));
$publish_success = $pubnub->publish(array('channel' => $channel, 'message' => trim($streams, ',')));
Example #3
0
<?php

## Capture Publish and Subscribe Keys from Command Line
$publish_key = "demo";
$subscribe_key = "demo";
$channel_name = "while-loop-channel";
## 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, '', false, 'pubsub.pubnub.com');
## ----------------------
## Send Message (PUBLISH)
## ----------------------
echo "Sending a message with Publish Function\n";
$start = microtime(1);
$tries = 100.0;
$i = 0;
$message = json_decode('{"id":"130051906964946945","type":"newtopic","created_at":"Fri Oct 28 22:42:45 +0000 2011","current_time":1319841837,"posted_at":1319841837,"reply_count":0,"from_user":"******","from_user_name":"Demo","profile_image_url":"http:\\/\\/a1.twimg.com\\/profile_images\\/1568426943\\/Screen_shot_2011-10-01_at_1.40.42_PM_normal.png","tweettext":"#uynb5598 ggttrru  <a href=\\"http:\\/\\/t.co\\/QkKBpjRS\\" rel=\\"nofollow\\" target=\\"_blank\\">http:\\/\\/t.co\\/QkKBpjRS<\\/a>","bubble_color":"","product_shorturl":null,"product_longurl":null,"media_type":"YFrog","message_video_url":null,"message_image_id":"21067","message_o_image_url":"http:\\/\\/c797842.r42.cf2.rackcdn.com\\/TIKZuz.jpg","message_l_image_url":"http:\\/\\/c797844.r44.cf2.rackcdn.com\\/TIKZuz.jpg","message_t_image_url":"http:\\/\\/c797843.r43.cf2.rackcdn.com\\/TIKZuz.jpg","message_f_image_url":null,"message_tvt_image_url":null,"message_tvl_image_url":null}');
#array( 'text' => $message );
while ($i++ < $tries) {
    $pubnub->publish(array('channel' => $channel_name, 'message' => $message));
}
## DONE
$end = microtime(1);
print_r(array('total publishes sent' => $tries, 'start' => $start, 'end' => $end, 'total test duration in seconds' => $end - $start, 'average delivery in seconds' => ($end - $start) / $tries, 'publishes per second' => $tries / ($end - $start)));
<?
require(dirname(__FILE__)."/../www/system/shared.php");
require(dirname(__FILE__)."/../www/system/Pubnub.php");

$db = Database::getInstance();
$confirmations = 0;

//Check for active monitors, order by ensures new events are attempted first
$res = $db->query("SELECT order_id,tx_hash,address,`value` FROM `active_uncomfirmed_monitors` ORDER BY order_id DESC");
if ($res->num_rows > 0)
{
	$pubnub = new Pubnub(PUBNUB_PUB, PUBNUB_SUB, "", false);
}

echo "Found ".$res->num_rows." rows \r\n";

while ($row = $res->fetch_array()) {
    $tx = $row['tx_hash'];
    $orderid = $row['order_id'];
    $address = $row['address'];
    $value = $row['value'];

    $success = true;

    $order = new Order($orderid);
    $user = new User($order->userid);

var_dump($order);
var_dump($user);

    foreach ($order->notifications as $notification) {
<?php

require_once 'Pubnub.php';
$pubnub = new Pubnub('demo', 'demo', false, false, false);
$pubnub->presence(array('channel' => 'testChannel', 'callback' => function ($message) {
    $fp = fopen('presenceOut.txt', 'w');
    fwrite($fp, serialize($message));
    fclose($fp);
    exit;
}));
## 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 ./chat-command-line.php PUBLISH-KEY SUBSCRIBE-KEY\n\n";
    exit;
}
## Require Pubnub API
echo "Connecting...\n";
echo "(Press ^C to exit)\n";
require '../Pubnub.php';
## -----------------------------------------
## Create Pubnub Client API (INITIALIZATION)
## -----------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key);
## ----------------------------------------
## Send/Recieve Message (PUBLISH/SUBSCRIBE)
## ----------------------------------------
$pid = pcntl_fork();
if ($pid == -1) {
    ## Fail :'(
    die('Could not fork. Get newer version of PHP!');
} else {
    if ($pid) {
        ## Get Username
        echo "ENTER USERNAME: "******"YOUR NAME IS {$user}\n\n";
        ## Listen for Messages From User
Example #7
0
## ---------------------------------------------------------------------------
## USAGE:
## ---------------------------------------------------------------------------
#
# php ./unit-test.php
# php ./unit-test.php [PUB-KEY] [SUB-KEY] [SECRET-KEY] [USE SSL]
#
## Capture Publish and Subscribe Keys from Command Line
$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');
## ---------------------------------------------------------------------------
<?php

## 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();
## ----------------------
## Send Message (PUBLISH)
## ----------------------
echo "Sending a message with Publish Function\n";
$start = microtime(1);
$tries = 50.0;
$success = 0;
$failes = 0;
$sent = 0;
while ($sent++ < $tries) {
    $info = $pubnub->publish(array('channel' => 'performance-test', 'message' => 'hi'));
    $info[0] && $success++;
    $info[0] || $failes++;
    $sent % (int) ($tries / 50) || (print '.');
}
## DONE
$end = microtime(1);
print "\n";
print_r(array('total successful publishes' => $success, 'total failed publishes' => $failes, 'total sequential publishes sent' => $tries, 'successful delivery rate' => '%' . $success / $tries * 100, 'failure delivery rate' => '%' . $failes / $tries * 100, 'total test duration in seconds' => $end - $start, 'average delivery in seconds' => ($end - $start) / $tries, 'publishes per second' => $tries / ($end - $start), 'start' => $start, 'end' => $end));
<?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.
?>

Example #10
0
<?php

require_once 'Pubnub.php';
$publish_key = isset($argv[1]) ? $argv[1] : 'demo';
$subscribe_key = isset($argv[2]) ? $argv[2] : 'demo';
$secret_key = isset($argv[3]) ? $argv[3] : false;
$cipher_key = isset($argv[4]) ? $argv[4] : false;
$ssl_on = false;
## Create Pubnub Object
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on);
## Define Messaging Channel
$channel = "hello_world";
## Subscribe Example
echo "\nWaiting for Publish message... Hit CTRL+C to finish.\n";
$pubnub->subscribe(array('channel' => $channel, 'callback' => function ($message) {
    print_r($message);
    echo "\r\n";
    return false;
}));
$publish_key = isset($argv[1]) ? $argv[1] : false;
$subscribe_key = isset($argv[2]) ? $argv[2] : false;
$channel_name = isset($argv[3]) ? $argv[3] : 'hello_world2';
# Print usage if missing info.
if (!($publish_key && $subscribe_key)) {
    echo "\n    ==============\n    EXAMPLE USAGE:\n    ==============\n    php ./subscribe-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);
## ------------------------------
## Listen for Message (SUBSCRIBE)
## ------------------------------
echo "Listening for Messages (Press ^C to stop)\n";
$pubnub->subscribe(array('channel' => $channel_name, 'callback' => function ($message) {
    ## REQUIRED Callback With Response
    var_dump($message);
    ## Print Message
    usleep(100);
    return true;
    ## Keep listening (return false to stop)
}));
?>

## Encryption Test
if (decrypt($cipher_text, $cipher_key) == $plain_text) {
    echo "Standard encryption test PASS.\n\n";
} else {
    echo "Standard encryption test FAIL.\n\n";
}
## Decryption Test
if (encrypt($plain_text, $cipher_key) == $cipher_text) {
    echo "Standard decryption test PASS.\n\n";
} else {
    echo "Standard decryption test FAIL.\n\n";
}
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key, $secret_key, $cipher_key, $ssl_on);
## ---------------------------------------------------------------------------
## Define Messaging Channel
## ---------------------------------------------------------------------------
$channel = "hello_world";
## ---------------------------------------------------------------------------
## Publish Example
## ---------------------------------------------------------------------------
echo "Running publish\r\n";
$publish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Pubnub Messaging API 1'));
echo $publish_success[0] . $publish_success[1];
echo "\r\n";
$publish_success = $pubnub->publish(array('channel' => $channel, 'message' => 'Pubnub Messaging API 2'));
echo $publish_success[0] . $publish_success[1];
echo "\r\n";
$publish_success = $pubnub->publish(array('channel' => $channel, 'message' => '漢語'));
<?php

require '../Pubnub.php';
$pubnub = new Pubnub('demo', 'demo');
$pubnub->subscribe(array('channel' => 'extra_cool_channel', 'callback' => function ($message) {
    var_dump($message);
    return true;
    ## continue listening
}));
<?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;
## Require Pubnub API
require '../Pubnub.php';
## -----------------------------------------
## Create Pubnub Client API (INITIALIZATION)
## -----------------------------------------
$pubnub = new Pubnub($publish_key, $subscribe_key);
## ----------------------
## Send Message (PUBLISH)
## ----------------------
$pubnub->subscribe(array('channel' => 'php_chat', 'callback' => function ($message) {
    ## REQUIRED Callback With Response
    ## Print Message
    echo "[" . date('H:i:s') . "] <" . $message['from'] . "> " . $message['text'] . "\r\n";
    ## Keep listening (return false to stop)
    return true;
}));
?>

<?php

require_once 'Pubnub.php';
$pubnub = new Pubnub('demo', 'demo', false, false, false);
$here = $pubnub->here_now(array('channel' => 'my_channel'));
$occupancy = $here['occupancy'];
$user_ids = $here['uuids'];
print "UUIDs (userIDs): ";
print_r($user_ids);
print "\n";
print "OCCUPANTS: {$occupancy}\n\n";