您好我想向所有已连接的客户端发送消息,但我的代码不起作用(对于一个用户来说是好的)
require_once('websockets.php');
$userConnected = array();
class echoServer extends WebSocketServer {
protected function process ($user, $exec) {
foreach($userConnected as $u) {
$this->send($u,'test');
}
}
protected function connected ($user) {
array_push($userConnected, $user);
}
protected function closed ($user) {
if(($key = array_search($user, $userConnected)) !== false) {
unset($userConnected[$key]);
}
}
}