private function request_write($args)
    {
        $request = json_encode($args)."\n";
        $this->last_request = $request;
        if (!$this->stream) {
            $desc = $this->request_description();
            throw new NetworkException("Unable to execute request ({$desc}): Connection closed");
        }

        // Must block while writing
        stream_set_blocking($this->stream, true);

        for ($written = 0; $written < strlen($request); $written += $fwrite) {
            $fwrite = fwrite($this->stream, substr($request, $written));
            if ($fwrite === false) {
                break;
            }
        }

        $this->request_count++;
    }