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\Handler\ErrorLogHandler;
use PubNub\PNConfiguration;
use PubNub\PubNub;

$pnconf = new PNConfiguration();

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

$pubnub = new PubNub($pnconf);

$pubnub->getLogger()->pushHandler(new ErrorLogHandler());

How to disable logging

You can disable the STDOUT print statements by configuring Monolog to use a different handler. Using Monolog\Handler\NullHandler instead of Monolog\Handler\ErrorLogHandler is the best option.

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

use Monolog\Handler\NullHandler;
use PubNub\PNConfiguration;
use PubNub\PubNub;

$pnconf = new PNConfiguration();

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

$pubnub = new PubNub($pnconf);

$pubnub->getLogger()->pushHandler(new Nullhandler());
Last updated on