protected function _GetResponse($fp, $client_ver)
    {
        $status = '';
        $response = '';
        $len = 0;
        $ver = '';

        $header = fread($fp, 8);
        if (strlen($header) == 8) {
            list($status, $ver, $len) = array_values(unpack('n2a/Nb', $header));
            $left = $len;
            while ($left > 0 && !feof($fp)) {
                $chunk = fread($fp, min(8192, $left));
                if ($chunk) {
                    $response .= $chunk;
                    $left -= strlen($chunk);
                }
            }
        }
        if ($this->_socket === false) {
            fclose($fp);
        }

        // check response
        $read = strlen($response);
        if (!$response || $read != $len) {
            $this->_error = $len
                ? "failed to read searchd response (status=$status, ver=$ver, len=$len, read=$read)"
                : 'received zero-sized searchd response';

            return false;
        }

        // check status
        if ($status == SEARCHD_WARNING) {
            list($temp, $wlen) = unpack('N*', substr($response, 0, 4));
            unset($temp);
            $this->_warning = substr($response, 4, $wlen);

            return substr($response, 4 + $wlen);
        }
        if ($status == SEARCHD_ERROR) {
            $this->_error = 'searchd error: '.substr($response, 4);

            return false;
        }
        if ($status == SEARCHD_RETRY) {
            $this->_error = 'temporary searchd error: '.substr($response, 4);

            return false;
        }
        if ($status != SEARCHD_OK) {
            $this->_error = "unknown status code '$status'";

            return false;
        }

        // check version
        if ($ver < $client_ver) {
            $this->_warning = sprintf("searchd command v.%d.%d older than client's v.%d.%d, some options might not work",
                $ver >> 8, $ver & 0xff, $client_ver >> 8, $client_ver & 0xff);
        }

        return $response;
    }