protected function openSocket(&$error_code, &$error_string)
  { 
    PHPCrawlerBenchmark::reset("connecting_server");
    PHPCrawlerBenchmark::start("connecting_server");

    // SSL or not?
    if ($this->url_parts["protocol"] == "https://") $protocol_prefix = "ssl://";
    else $protocol_prefix = "";
    
    // If SSL-request, but openssl is not installed
    if ($protocol_prefix == "ssl://" && !extension_loaded("openssl"))
    {
      $error_code = PHPCrawlerRequestErrors::ERROR_SSL_NOT_SUPPORTED;
      $error_string = "Error connecting to ".$this->url_parts["protocol"].$this->url_parts["host"].": SSL/HTTPS-requests not supported, extension openssl not installed.";
    }
    
    // Get IP for hostname
    $ip_address = $this->DNSCache->getIP($this->url_parts["host"]);

    // since PHP 5.6 SNI_server_name is deprecated
    if (version_compare(PHP_VERSION, '5.6.0') >= 0)
    {
      $serverName = 'peer_name';
    }
    else
    {
      $serverName = 'SNI_server_name';
    }
    
    // Open socket
    if ($this->proxy != null)
    {
      $this->socket = @stream_socket_client($this->proxy["proxy_host"].":".$this->proxy["proxy_port"], $error_code, $error_str,
                                           $this->socketConnectTimeout, STREAM_CLIENT_CONNECT);
    }
    else
    {
      // If ssl -> perform Server name indication
      if ($this->url_parts["protocol"] == "https://")
      {
        $context = stream_context_create(array(
          'ssl' => array(
            $serverName => $this->url_parts["host"],
          ),
        ));
        $this->socket = @stream_socket_client($protocol_prefix.$ip_address.":".$this->url_parts["port"], $error_code, $error_str,
                                              $this->socketConnectTimeout, STREAM_CLIENT_CONNECT, $context);
      }
      else
      {
        $this->socket = @stream_socket_client($protocol_prefix.$ip_address.":".$this->url_parts["port"], $error_code, $error_str,
                                              $this->socketConnectTimeout, STREAM_CLIENT_CONNECT); // NO $context here, memory-leak-bug in php v. 5.3.x!!
      }
    }
    
    $this->server_connect_time = PHPCrawlerBenchmark::stop("connecting_server");
        
    // If socket not opened -> throw error
    if ($this->socket == false)
    { 
      $this->server_connect_time = null;
      
      // If proxy not reachable
      if ($this->proxy != null)
      {
        $error_code = PHPCrawlerRequestErrors::ERROR_PROXY_UNREACHABLE;
        $error_string = "Error connecting to proxy ".$this->proxy["proxy_host"].": Host unreachable (".$error_str.").";
        return false;
      }
      else
      {
        $error_code = PHPCrawlerRequestErrors::ERROR_HOST_UNREACHABLE;
        $error_string = "Error connecting to ".$this->url_parts["protocol"].$this->url_parts["host"].": Host unreachable (".$error_str.").";
        return false;
      }
    }
    else
    {
      return true;
    }
  }