Pubnub没有通过在php中编写的subscribe显示输出

时间:2016-06-01 08:17:18

标签: php pubnub

我尝试从不同的浏览器执行PubNub发布/订阅代码。首先,我执行了pubnub_subscribe.php文件,然后执行了pubnub_publish.php。 pubnub_publish.php代码显示以下输出。我已经注册了PubNub。我无法在发布和订阅中看到该消息。 任何人都可以指导我如何找到答案。我们将不胜感激。

输出(在pubnub_publish.php中)

jsPlumb.draggable(newAgent, {
                containment: 'parent'
            });
            newAgent.on('click', '.cancel', function (e) {

                alert( newAgent.attr('id'));
                var elementId= newAgent.attr('id');
                var regEx = '/['+elementId+']*/';
                alert (regEx);

                for(var m=0; m<list.length; m++)
                {
                    if(list[m][0].exec(regEx) || list[m][1].exec(regEx))
                    {
                        alert('Deleting connection between ' + list[m][0] + '&' + list[m][1]);
                    }
                }

                jsPlumb.detachAllConnections(newAgent.attr('id'));
                jsPlumb.removeAllEndpoints(newAgent.attr('id'));
                jsPlumb.detach(newAgent.attr('id'));
                $(newAgent).remove();
            });

pubnub_publish.php

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

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)
                    );
$publish_result = $pubnub->publish('Channel-m2cerlovh','Hello PubNub!');
print_r($publish_result);
?>

1 个答案:

答案 0 :(得分:0)

PubNub发布/订阅

您要发布到Channel-m2cerlovh并订阅Channel-n9zu05kxi。只有Channel-m2cerlovh的订阅者才会收到发布到该频道的消息。

此外,无需将subscribeTimeout设置为10s。那太低了。只需删除该行代码并使用默认值(除非你有一些奇怪的边缘情况来证明这个设置 - 然后我很想知道为什么)。

在这个公共论坛中包含发布和子密钥并不是一个好主意。我会禁用该密钥集并使用新的集合(我在你的问题中将其截断)。