0

I have tried executing the PubNub publish/subscribe code from the different browsers. First I have executed pubnub_subscribe.php file, then pubnub_publish.php. pubnub_publish.php code shows the following output. I have already register with PubNub. I can not see the message in publish and subscribe. Could anyone guide me how to find out the answer. It will be appreciated.

output (in pubnub_publish.php)

Array ( [0] => 1 [1] => Sent [2] => 14647684832679527 )

pubnub_publish.php

<?php
require_once('Pubnub/lib/autoloader.php');
use Pubnub\Pubnub;
$publish_key = "pub-c-34b22d9f...";
$subscribe_key = "sub-c-54cb22de...";
$pubnub = new Pubnub(array("publish_key" =>$publish_key, 
                    "subscribe_key" =>$subscribe_key,
                    "ssl" => true,
                    "uuid" =>"user1",
                    'verify_peer' => true)
                    );
$publish_result = $pubnub->publish('Channel-m2cerlovh','Hello PubNub!');
print_r($publish_result);
?>

pubnub_subscribe.php

<?php
require_once('Pubnub/lib/autoloader.php');
use Pubnub\Pubnub;

$publish_key = "pub-c-34b22d9f...";
$subscribe_key = "sub-c-54cb22de...";
$pubnub = new Pubnub(array("publish_key" =>$publish_key, 
                    "subscribe_key" =>$subscribe_key,
                    "ssl" => true,
                    "uuid" =>"user1",
                    'verify_peer' => true)
                    );

$pubnub->setSubscribeTimeout(10); 

$pubnub->subscribe('Channel-n9zu05kxi', function ($envelope) {
       print_r($envelope['message']);
});
?>
Craig Conover
  • 4,710
  • 34
  • 59
Jaymesh
  • 11
  • 4

1 Answers1

0

PubNub Publish/Subscribe

You are publishing to Channel-m2cerlovh and subscribing to Channel-n9zu05kxi. Only subscribers to Channel-m2cerlovh will receive messages published to that channel.

Also, no need to set the subscribeTimeout to 10s. That is too low. Just remove that line of code and use the default (unless you have some strange edge case to justify this setting - then I would be curious to know why).

And not a good idea to include you pub and sub key in this public forum. I would disable that key set and use a new set (I truncated them in your question).

Community
  • 1
  • 1
Craig Conover
  • 4,710
  • 34
  • 59