Reputation: 1229
I am building a chat based on Comet technology and I am stuck with this problem. So, for comet, i am using ningx with it's push module. Everything works fine. I can send messages to another user via dedicated channels. However, the problem appeared when I started thinking what will happen to the message which was sent to a user who went offline before receiving that message. I'd like before pushing the message into a channel to check if the receiver is still listening that channel. If so, I will just push the message otherwise I want just put the message into the database so that the user could read it when he/she is online.
QUESTION:
Thanks!
Upvotes: 0
Views: 223
Reputation: 1229
I've answered on my own question. Here's the code I use to publish a message and how I get an useful information back after publishing it.
$channel_id = 'c'.$_POST['uid'];
$message['sender']=$_SESSION['user.ID'];
$message['firstname']=$_SESSION['user.firstname'];
$message['message']=$_POST['msg'];
$message['type']='chat';
$c = curl_init('http://192.168.56.101/publish?cid='.$channel_id);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, 'pre('.json_encode($message).')');
$r = curl_exec($c);
in this example var $r contains this: queued messages: 0 last requested: 4 sec. ago (-1=never) active subscribers: 1
as u can see, it also contains a number of subscribers
Upvotes: 1