예제 #1
0
<?php

/**
 * Run this script and publish any message to the "foo.bar" channel via
 * Pubnub Console: http://www.pubnub.com/console/
 *
 * This message should be received in subscribe callback.
 */
require_once "../composer/lib/autoloader.php";
$pubnub = new Pubnub\Pubnub(["publish_key" => "demo-36", "subscribe_key" => "demo-36"]);
$pubnub->subscribe(["foo.*"], function ($message) {
    echo "Channel message:\n";
    print_r($message);
});
예제 #2
0
<?php

/**
 * Run this script and publish any message to the "ch1" channel via
 * Pubnub Console: http://www.pubnub.com/console/
 *
 * This message should be received in channelGroupSubscribe callback.
 */
require_once "../composer/lib/autoloader.php";
$pubnub = new Pubnub\Pubnub("demo", "demo");
$pubnub->channelGroupAddChannel("php_manual_test", ["ch1"]);
$channels = $pubnub->channelGroupListChannels("blah");
$pubnub->channelGroupSubscribe("php_manual_test", function ($message) {
    echo "Channel group message:\n";
    print_r($message);
});
예제 #3
0
## PARAMATERS AND SETTINGS
## ---------------------------------------------------------------------------
## screen -d -m -S <TICK> php stock.php <TICK> <PRICE> <MIN> <MAX> <VOL> <D>
## ---------------------------------------------------------------------------
## Timezone
## ---------------------------------------------------------------------------
date_default_timezone_set('America/New_York');
setlocale(LC_MONETARY, "en_US");
## Capture Publish and Subscribe Keys from Command Line
$publish_key = isset($argv[7]) ? $argv[7] : 'demo';
$subscribe_key = isset($argv[8]) ? $argv[8] : 'demo';
$auth_key = isset($argv[9]) ? $argv[9] : '';
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub\Pubnub(['publish_key' => $publish_key, 'subscribe_key' => $subscribe_key, 'auth_key' => $auth_key]);
## ---------------------------------------------------------------------------
## Define Stock Ticker Setup
## ---------------------------------------------------------------------------
$channel = $argv[1];
$sPrice = $argv[2];
$minTrade = $argv[3];
$maxTrade = $argv[4];
$volatility = $argv[5];
$maxDelta = $argv[6];
echo $channel . "\n";
echo $sPrice . "\n";
## ---------------------------------------------------------------------------
## Publish Example
## ---------------------------------------------------------------------------
echo "Running publish\r\n";
예제 #4
0
## USAGE:
## ---------------------------------------------------------------------------
## php ./bootstrap.php
## 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;
$auth_key = isset($argv[4]) ? $argv[4] : false;
$group = "stockblast";
$chat = "stock-chat";
$history = "MSFT";
$bootstrap_auth = $auth_key . "-bootstrap";
## ---------------------------------------------------------------------------
## Create Pubnub Object
## ---------------------------------------------------------------------------
$pubnub = new Pubnub\Pubnub($publish_key, $subscribe_key, $secret_key);
$pubnub->setAuthKey($bootstrap_auth);
## ---------------------------------------------------------------------------
## Find all Streams running on this system
## ---------------------------------------------------------------------------
echo "Active stocks: ";
$streams = system(implode(' | ', array('ps a', 'grep stock.php', 'grep -v grep', 'awk "{print \\$7}"', 'tr "\\n+" ","')));
echo "\n";
$channels = explode(",", trim($streams, ","));
## ---------------------------------------------------------------------------
## Grant permissions (will not work for a "demo/demo" credentials)
## ---------------------------------------------------------------------------
## To stocks channel group
$response = $pubnub->pamGrantChannelGroup(1, 0, $group);
validateResponse($response);
## To current instance
예제 #5
0
<?php

/**
 * Run this script and publish any message to the "php_manual_test" channel via
 * Pubnub Console: http://www.pubnub.com/console/
 *
 * This message should be received in subscribe callback.
 */
require_once "../composer/lib/autoloader.php";
$pubnub = new Pubnub\Pubnub("demo", "demo");
$pubnub->subscribe("php_manual_test", function ($message) {
    echo "Channel message:\n";
    print_r($message);
});