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 to a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds channels to a channel group.
Method(s)
Adding Channels
is accomplished by using the following method(s) in the PHP SDK:
Maximum number of channels
You can add up to 200 channels to a 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 channel group to add the channels to. |
Sample code
Add channels
Reference code
Rest response from server
{
"service" : "channel-registry",
"status" : 200,
"error" : false,
"message" : "OK"
}
List channels in a 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 lists all channels in a 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 for which to list channels. |
Sample code
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 from a 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 channels from a 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 | The channels to remove from the channel group. |
channelGroup *Type: String | The channel group from which to remove the channels. |
Sample code
Remove channels
$pubnub->removeChannelFromChannelGroup()
->channels("son")
->channelGroup("family")
->sync();
Rest response from server
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}
Delete a 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 deletes a 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 channel group to remove. |
Sample code
Delete channel group
$pubnub->removeChannelGroup()
->channelGroup("family")
->sync();
Rest response from server
{
"status" : 200,
"message" : "OK",
"service" : "channel-registry",
"error" : False
}