protected function _getSocket()
    {
        if (is_resource($this->_socket)) {
            if (feof($this->_socket)) {
                // Supervisor sometimes seems to close the socket after a request is completed, which
                // causes the following request made by SupervisorClient to fail mysteriously with an
                // error about a missing content-length header.  This check takes care of this issue.
                fclose($this->_socket);
            } else {
                // Check if the socket already exists and is open, if it is return it.
                return $this->_socket;
            }
        }

        // Open the socket.
        $this->_socket = @fsockopen(
            $this->_hostname,
            $this->_port,
            $errno,
            $errstr,
            $this->_timeout
        );

        if (!$this->_socket) {
            throw new Exception(sprintf("Cannot open socket: Error %d: \"%s\"", $errno, $errstr));
        }

        stream_set_timeout($this->_socket, $this->_timeout);

        return $this->_socket;
    }