Channel Groups API for PHP SDK
Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.
Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
Add Channels
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds a channel to a channel group.
Method(s)
Adding Channels
is accomplished by using the following method(s) in the PHP SDK:
Maximum number of channels
200 channels
can be added to the channel group
per API call.
$pubnub->addChannelToChannelGroup()
->channels(string|array)
->channelGroup(string)
->sync();
Parameter | Description |
---|---|
channels *Type: String|Array | The channels to add to the channel group. |
channelGroup *Type: String | The channelGroup to add the channels to. |
Basic Usage
Add Channels
Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
<?php
// Include Composer autoloader (adjust path if needed)
require_once 'vendor/autoload.php';
use PubNub\PNConfiguration;
use PubNub\PubNub;
use PubNub\Exceptions\PubNubServerException;
// Create configuration
$pnConfig = new PNConfiguration();
$pnConfig->setSubscribeKey("demo");
$pnConfig->setPublishKey("demo");
$pnConfig->setUserId("php-channel-group-demo");
show all 47 linesRest Response from Server
{
"service" : "channel-registry",
"status" : 200,
"error" : false,
"message" : "OK"
}
List Channels
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function lists all the channels of the channel group.
Method(s)
Listing Channels
is accomplished by using the following method(s) in the PHP SDK:
$pubnub->listChannelsInChannelGroup()
->channelGroup(string)
->sync();
Parameter | Description |
---|---|
channelGroup *Type: String | The channel group to fetch channels. |
Basic Usage
List Channels
$pubnub->listChannelsInChannelGroup()
->channelGroup("cg1")
->sync();
Rest Response from Server
{
"status" : 200,
"payload" : {
"channels" : ["hi"],
"group" : "abcd"
},
"service" : "channel-registry",
"error" : False
}
Remove Channels
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes the channels from the channel group.
Method(s)
Removing Channels
is accomplished by using the following method(s) in the PHP SDK:
$pubnub->removeChannelFromChannelGroup()
->channels(string|array)
->channelGroup(string)
->sync();
Parameter | Description |
---|---|
channels *Type: String|Array | channels to remove from the channel group. |
channelGroup *Type: String | Specifies ChannelGroup to remove. |
Basic Usage
Remove channels
$pubnub->removeChannelFromChannelGroup()
->channels("son")
->channelGroup("family")
->sync();
Rest Response from Server
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}
Delete Channel Group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes the channel group.
Method(s)
Deleting Channel Group
is accomplished by using the following method(s) in the PHP SDK:
$pubnub->removeChannelGroup()
->channelGroup(string)
->sync();
Parameter | Description |
---|---|
channelGroup *Type: String | The channelGroup to remove. |
Basic Usage
Delete Channel Group
$pubnub->removeChannelGroup()
->channelGroup("family")
->sync();
Rest Response from Server
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}