Пример #1
0
 private function onMessage($connect, $data)
 {
     echo SocketHelpers::decode($data)['payload'] . "\n";
 }
Пример #2
0
 public function checkConnection()
 {
     $this->_connected = false;
     // send ping:
     $data = 'ping?';
     @fwrite($this->_Socket, SocketHelpers::encode($data, 'ping', true));
     $response = @fread($this->_Socket, 300);
     if (empty($response)) {
         return false;
     }
     $response = SocketHelpers::decode($response);
     if (!is_array($response)) {
         return false;
     }
     if (!isset($response['type']) || $response['type'] !== 'pong') {
         return false;
     }
     $this->_connected = true;
     return true;
 }