server = $server; $this->path = $path; $this->port = $port; } function query() { $args = func_get_args(); $method = array_shift($args); // Now send the request $this->fp = @fsockopen($this->server, $this->port); if (!$this->fp) { $this->error = 'transport error - could not open socket'; return false; } // construct packet and transmit $packet = serialize(array($method, $args)); $request = implode(":", array(strlen($packet), md5($packet), $packet)); fputs($this->fp, $request); // get header $contents = fgets($this->fp, 50); $response = explode(":", $contents, 3); // returns len, hash, packet $len = $response[0]; $hash = $response[1]; $packet = $response[2]; $rest = $len - strlen($packet); // complete response $packet .= fgets($this->fp, $rest + 1); if ($this->debug) { echo $packet; } // todo check hash return unserialize($packet); } } ?>