Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何仅使用Pusher向个人触发事件?_Php_Chat_Pusher - Fatal编程技术网

Php 如何仅使用Pusher向个人触发事件?

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

我用PHP和Pusher API编写了一个聊天程序。 现在,我试图触发一个事件给一个单独的用户,但我不知道怎么做。 每个用户都由会话用户名标识。 这是我触发消息的方式:

$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
);
可能重复的