Troubleshooting PubNub PHP SDK

How to enable logging

Required UUID

Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the UUID, you won't be able to connect to PubNub.

use Monolog\Level;
use Monolog\Logger;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Handler\StreamHandler;
use PubNub\PNConfiguration;
use PubNub\PubNub;

$pnconf = new PNConfiguration();
$pnconf->setPublishKey('pub_key');
$pnconf->setSubscribeKey('sub_key');
$pnconf->setUserId('example');

$logger = new Logger('pubnub');
$logger->pushHandler(new StreamHandler('php://stdout', Level::Info));

show all 19 lines

How to disable logging

You can disable the STDOUT print statements by ommiting configuration of logger. Default PSR/Log/NullLogger will be used.

Using this code sample you can discard all log message output:

use PubNub\PNConfiguration;
use PubNub\PubNub;

$pnconf = new PNConfiguration();

$pnconf->setPublishKey("pub_key");
$pnconf->setSubscribeKey("sub_key");
$pnconf->setUserId('example');

$pubnub = new PubNub($pnconf);
Last updated on