Exemplo n.º 1
3
<?php

require_once __DIR__ . '/../lib/autoloader.php';
use Pubnub\Pubnub;
$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, 'IUNDERSTAND.pubnub.com');
## Define Messaging Channel
$channel = "php_exit";
## 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;
}));
Exemplo n.º 2
0
 public function __invoke(ClosureDaemon $daemon)
 {
     $this->daemon = $daemon;
     $camera = $this->gopro;
     $darkroom = $this->darkroom;
     error_log('subscribed to channel: ' . $this->channel);
     $this->pubnub->subscribe($this->channel, [$this, 'process']);
     return $this->daemon->run;
 }
Exemplo n.º 3
0
 protected function subscribeAtPubnub()
 {
     if (!$this->alive()) {
         throw new Exception('Subscription is not alive');
     }
     $this->_pubnub = $this->_pubnubFactory->pubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->_subscription['deliveryMode']['subscriberKey']));
     $this->_pubnub->subscribe($this->_subscription['deliveryMode']['address'], array($this, 'notify'));
     return $this;
 }
Exemplo n.º 4
0
 protected function subscribeAtPubnub()
 {
     if (!$this->alive()) {
         throw new Exception('Subscription is not alive');
     }
     $this->_pubnub = $this->_pubnubFactory->pubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->_subscription['deliveryMode']['subscriberKey']));
     $this->_pubnub->setSubscribeTimeout(self::SUBSCRIBE_TIMEOUT);
     $this->_pubnub->subscribe($this->_subscription['deliveryMode']['address'], array($this, 'notify'), 0, false, array($this, 'pubnubTimeoutHandler'));
     return $this;
 }
Exemplo n.º 5
0
 /**
  * @group subscribe
  * @group subscribe-errors
  */
 public function testSubscribeWithInvalidCredentials()
 {
     $test = $this;
     $pubnub = new Pubnub("invalid", "credentials");
     $pubnub->subscribe("error_test", function ($response) use($test) {
         $test->assertTrue($response['error']);
         $test->assertEquals("Invalid Subscribe Key", $response['message']);
         return false;
     });
 }
 protected function subscribeAtPubnub()
 {
     if (!$this->isSubscribed()) {
         return $this;
     }
     $this->pubnub = $this->pubnubFactory->getPubnub(array('publish_key' => 'convince-pubnub-its-okay', 'subscribe_key' => $this->subscription['deliveryMode']['subscriberKey']));
     //print 'PUBNUB object created' . PHP_EOL;
     $this->pubnub->subscribe($this->subscription['deliveryMode']['address'], array($this, 'notify'));
     //print 'PUBNUB subscription created' . PHP_EOL;
     return $this;
 }
 /**
  * Subscribe to given channel.
  *
  * @param  string $channel
  * @param  Closure $callback
  * @return void
  */
 public function subscribe($channel, Closure $callback)
 {
     $this->pubnub->subscribe($channel, $callback);
 }
Exemplo n.º 8
0
<?php

require 'vendor/autoload.php';
use Pubnub\Pubnub;
$pubnub = new Pubnub("pub-c-c22bf29d-2eba-48c2-84f5-1946ed66539e", "sub-c-2556ee06-7916-11e5-9720-0619f8945a4f", "client0001");
$pubnub->subscribe('hello_world', function ($envelope) {
    $msg = $envelope['message'];
    print_r($envelope);
    if (strcmp($msg, "exit") == 0) {
        print_r('<<< So long, and thanks for all the messages! >>>');
        return false;
    } else {
        print_r('>>> May I have some more message, please? <<<');
        return true;
    }
});
Exemplo n.º 9
0
<?php

require_once 'autoloader.php';
use Pubnub\Pubnub;
// Create Pubnub Object
$pubnub = new Pubnub('pub-c-a9afac0f-597a-4d95-a975-83b16220f02b', 'sub-c-2023456c-d1a2-11e5-bcee-0619f8945a4f', false, false, false, 'IUNDERSTAND.pubnub.com');
// Define Messaging Channel
$channel = $_REQUEST['auth_code'];
echo "\nWaiting for Publish message... Hit CTRL+C to finish.\n";
$pubnub->subscribe($channel, function ($message) {
    print_r($message);
    echo "\r\n";
    flush();
    ob_flush();
    return true;
});