public function send(Packet $packet) { $conn = $this->connection(); $bytes = $packet->getBinary(); fputs($conn, $bytes, strlen($bytes)); // TODO: Check result checksum! $result = fread($conn, 8192); if ($result === false) { throw new \Exception('CHECK_NRPE: Error receiving data from daemon.'); } elseif (strlen($result) === 0) { throw new \Exception('CHECK_NRPE: Received 0 bytes from daemon.' . ' Check the remote server logs for error messages'); } // TODO: CHECK_NRPE: Receive underflow - only %d bytes received (%d expected) $code = unpack('n', substr($result, 8, 2)); $this->lastReturnCode = $code[1]; $this->disconnect(); return rtrim(substr($result, 10, -2)); }