/** * @param string $data * @return int|bool */ public function send($data) { if (substr($data, -1) != "\n") { $data .= "\n"; } $this->event->callWriteListeners($data, $this); // http://php.net/manual/function.fwrite.php#refsect1-function.fwrite-notes for ($written = 0; $written < strlen($data); $written += $fwrite) { if ($this->feof()) { throw new SocketDisconnectedException(); } $w = array($this->socket); $r = $e = null; stream_select($r, $w, $e, 0); $fwrite = fwrite($this->socket, substr($data, $written)); if ($fwrite === false) { return $fwrite; } } return $written; }