Php 如何仅使用Pusher向个人触发事件?
我用PHP和Pusher API编写了一个聊天程序。 现在,我试图触发一个事件给一个单独的用户,但我不知道怎么做。 每个用户都由会话用户名标识。 这是我触发消息的方式:Php 如何仅使用Pusher向个人触发事件?,php,chat,pusher,Php,Chat,Pusher,我用PHP和Pusher API编写了一个聊天程序。 现在,我试图触发一个事件给一个单独的用户,但我不知道怎么做。 每个用户都由会话用户名标识。 这是我触发消息的方式: $pusher->trigger( 'presence-nettuts', //the channel 'new_message', //the event array('message' => $message) //the data to send ); //ec
$pusher->trigger(
'presence-nettuts', //the channel
'new_message', //the event
array('message' => $message) //the data to send
);
//echo the success array for the ajax call
echo json_encode(array(
'message' => $message,
'success' => true
));
exit();
我只想将事件定向到在线用户,该用户通过使用会话的用户名识别
你能告诉我怎么做吗
谢谢。您的频道名称对该用户来说应该是唯一的。 因此,一种可能性是使用用户名等独特的内容创建频道:
$pusher->trigger(
'presence-nettuts-'.$username, //the channel
'new_message', //the event
array('message' => $message) //the data to send
);
可能重复的