array('min' => 1, 'max' => 2)); function Intermission($daemon_socket) { $this->sock = socket_create(AF_UNIX, SOCK_STREAM, 0); socket_connect($this->sock, $daemon_socket); $this->daemon_version = $this->sock_write($this->version); } function parse($data) { if ($data[1]) { return $data[1]; } else { return $data[0]; } } function sock_close() { socket_close($this->sock); } function sock_read() { return bdecode(socket_read($this->sock, hexdec(socket_read($this->sock, 8)))); } function sock_write($data, $response = true, $parsed = false) { $data = bencode($data); socket_write($this->sock, sprintf('%08X', strlen($data)) . $data); if ($response) { if ($parsed) { return $this->parse($this->sock_read()); } else { return $this->sock_read(); } } } } ?>