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.
1$pubnub->addChannelToChannelGroup()
2 ->channels(string|array)
3 ->channelGroup(string)
4 ->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
1
Rest response from server
1{
2 "service" : "channel-registry",
3 "status" : 200,
4 "error" : false,
5 "message" : "OK"
6}
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:
1$pubnub->listChannelsInChannelGroup()
2 ->channelGroup(string)
3 ->sync();
Parameter | Description |
---|---|
channelGroup *Type: String | The channel group for which to list channels. |
Sample code
List channels
1$pubnub->listChannelsInChannelGroup()
2 ->channelGroup("cg1")
3 ->sync();
Rest response from server
1{
2 "status" : 200,
3 "payload" : {
4 "channels" : ["hi"],
5 "group" : "abcd"
6 },
7 "service" : "channel-registry",
8 "error" : False
9}
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:
1$pubnub->removeChannelFromChannelGroup()
2 ->channels(string|array)
3 ->channelGroup(string)
4 ->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
1$pubnub->removeChannelFromChannelGroup()
2 ->channels("son")
3 ->channelGroup("family")
4 ->sync();
Rest response from server
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}
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:
1$pubnub->removeChannelGroup()
2 ->channelGroup(string)
3 ->sync();
Parameter | Description |
---|---|
channelGroup *Type: String | The channel group to remove. |
Sample code
Delete channel group
1$pubnub->removeChannelGroup()
2 ->channelGroup("family")
3 ->sync();
Rest response from server
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}