My application users log on, log off and then later log on again. How do I discard queued messages from the old session?

There are two solutions to address this:

  1. Set restore:false. This will prevent old messages from being sent to a user that logged off and back on again.
  2. Include timestamps with published messages. Your application can ignore messages dating before a set delay.

Here is an example for the 2nd solution in PHP:

$t = time() . "";
$m = array("serial" => $t, "payload" => "Hello from PHP! " . $t);
$publish_success = $pubnub->publish(array('channel' => $c, 'message' => $m));

In this example, the serial attribute is set to the timestamp of the message being published. By tracking the serial number on the client, you can verify if a message was received already.