title: PubNub publish message between two Private Channels
body: <p>I'm using Php and MySQL.</p>
  
  <p>I have just signup for pubnub push API and successfully made my first push notification using the PHP Push API provided by Pubnub. I'm new into this Realtime technology so I have come up with some questions which I find confusing to understand myself. I have googled many times and searched all over stackoverflow. I didn't get any relevant suggestions or questions elsewhere, so I'm writing down my question here seeking your advice and expertise help.</p>
  
  <p>Pubnub says it's not a good thing to create more than two channels per client. So, in my application, I have a requirement to create more than two channels to listen to notifications happening everywhere on my website but I will go with two channels for every logged in users as Pubnub suggested.</p>
  
  <ol>
  <li>Logged in users listens to Channel1-Public <br/></li>
  <li>Logged in users listens to private UsersOwnDynamic-Channel to receive notifications related and only meant for him.</li>
  </ol>
  
  <p>FYI: <a href="https://help.pubnub.com/entries/21115547-how-do-i-allow-only-certain-users-to-subscribe-to-certain-channels" rel="nofollow noreferrer">This link in PubNub says about creating LongChannel names to avoid Channel Snooping</a></p>
  
  <p>My questions are given below: <br/>
  A. Do I always have to create a new private Dynamic channel name everytime I logged into the website. If so, how would other users know how to send a notification to my private Channel.Or, do I just need to have only one static channel name stored in database table, so that other authenticated users will query the table and get my private channel name to sent me notifications. If this is the case, don't you think if a hacker get hold of some private channel name of certain users, they will be able to listen to that channel?</p>
  
  <p>B.I'm using PHP and MySQL, so I still cannot think out a way or come up with a solution to send message to private channels of another user. <br/>
  Lets take an example for a simple friend request system. <br/>
  - UserA sends a friend request to UserB. <br/>
  - UserB is listening to his own dynamic private channel name called DynamicPrivateChannelB <br/>
  (how will UserA find the channel name for UserB which is private? Im thinking the only way for this is that the private channel of UserB should be stored in a database table for every loggedin users to query. Am I thinking the right way ? )</p>
  
  <pre><code>&lt;?php 
  
      //first way. How can i possibly achieve this.
      $sqlquery = "sent friend request from userA to userB"; 
      require('Pubnub.php'); 
      $pubnub = new Pubnub( 'pubkey', 'subkey' );
      $pubnub-&gt;publish( array(
          'channel' =&gt; 'how do i find the private channel name for userB to sent this notification?', 
                      'message' =&gt; array('friend_request' =&gt; 'A friend request') ) 
                      );
  
    //2nd way ? Is this the right way ?
      $sqlquery = "sent friend request from userA to userB"; 
      $privatechannelofuserB = "get the channel name of userB from the db table";
      require('Pubnub.php'); 
      $pubnub = new Pubnub( 'pubkey', 'subkey' );
      $pubnub-&gt;publish( array(
          'channel' =&gt; '$privatechannelofuserB', 
                      'message' =&gt; array('friend_request' =&gt; 'A friend request') ) 
                      );
  ?&gt;
  </code></pre>
  
  <p>C. If we are always generating dynamic private channel names, storing in database table, updating whenever new dynamic channel names are generated. I think it will cause a problem because some message won't get delivered as new dynamic private channel names replaces old ones.</p>
  
  <p>D. So, I have many notifications to sent to a single channel like New Friends request, New Private message replies, New gifts requests and many others like that. How do I sent all these data to a channel and how to find out and parse the incoming new notifications data. I know JSON is the format to send but im not sure about the format of sending.
  <br/><br/></p>
  
  <p>According to <a href="https://help.pubnub.com/entries/21115547-how-do-i-allow-only-certain-users-to-subscribe-to-certain-channels" rel="nofollow noreferrer">this link</a>, a single Pubnub channel can contain only up to 100 messages. Does it mean that if 200 messages comes at once to a single channel the first 100 gets delivered and the remaining is on queue ? How about if 10,000 messages comes at once to a single channel ? Do all the remaining messages stays in queue ? if so, how does it gets delivered to the subscriber in realtime ?
  <br/><br/>
  Let me give another simple scenario that I'm trying to achieve. <br/></p>
  
  <blockquote>
    <ul>
    <li><strong>UserA</strong> is authenticated and logged in to the website. <br/></li>
    <li><strong>UserA</strong> generates his own Dynamic channel name, <strong>UserAx732dsw3efsdfsdfsdf</strong> <br/></li>
    <li><strong>UserA</strong> starts listening to his newly created channel <strong>UserAx732dsw3efsdfsdfsdf</strong> <br/> (Now, userA should start receiving messages from others) <br/></li>
    </ul>
    
    <p><br/>
    - <strong>UserB</strong> sends a private message to <strong>userA</strong>. <br/> (Now, only userA should get notified on his private channel about the new private
    message, how can <strong>userB</strong>  or the <strong>System</strong> find out the channel
    name <strong>UserAx732dsw3efsdfsdfsdf</strong> because, this is a private channel
    generated dynamically by <strong>userA</strong> , neither the <strong>System</strong> or
    <strong>userB</strong> has accessed to it. This same thing is happening for <strong>userB</strong> as well, if <strong>userB</strong> should be notified by any other entity or by the system again, there should be a way to find out the dynamic
    channel name of <strong>userB</strong> . <br/>
    <br/>
    Another issue is this scenario is that, if a user is dynamically generating channel name everytime he/she logged in to the website. What will happen to all the messages that was sent to the dynamic channel ? Do pubnub saves all the created channel names on their server? Is there any way that a system or a user can find out whether a channel name is still being own and atleast one user is listening to the channel ?.  <br/> <br/>
    I'm curious to know this because of the following concepts that I have: <br/></p>
    
    <ul>
    <li><strong>UserA</strong> creates <strong>dynamicChannelA</strong> when he/she logged in to the website at <strong>1AM</strong>. <br/></li>
    <li>UserA starts getting lots of notification pushout to his dynamic channel <strong>dynamicChannelA</strong> <br/></li>
    <li>Now, <strong>UserA</strong> logs out from the website at <strong>1:30 AM</strong>, what will happen to the many other users who are still pushing out notification
    to his <strong>dynamicChannelA</strong> because by the next time when <strong>UserA</strong>
    logs into the website, <strong>UserA</strong> will be listening to different
    dynamic channel name.<strong>UserA</strong> won't be listening to his previous
    channel <strong>dynamicChannelA</strong> .</li>
    </ul>
  </blockquote>
  
  <p><br/>
  I'm thinking to use the method of retrieving channel name of a particular user from the database table. Is there any method or way to prevent unauthorised subscription of the channel? Because anybody can subscribe to the channel name if they have the subscribe key and channel name no matter how long the channel name is. I'm just curious because all subscription is happening in the client side and the subscription key and channel names are visible.</p>