diff --git a/httprl.module b/httprl.module index 36edd12..7cebda9 100755 --- a/httprl.module +++ b/httprl.module @@ -132,6 +132,7 @@ function httprl_build_url_self($path = '', $detect_schema = FALSE) { */ function httprl_request($url, array $options = array()) { global $base_root; + static $https_flags; $result = new stdClass(); // Parse the URL and make sure we can handle the schema. @@ -195,12 +196,26 @@ function httprl_request($url, array $options = array()) { return $result; } + $flags = STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT; + + // Workaround for PHP bug with STREAM_CLIENT_ASYNC_CONNECT and SSL + // https://bugs.php.net/bug.php?id=48182 - Fixed in PHP 5.2.11 and 5.3.1 + if ($uri['scheme'] == 'https') { + if (!isset($https_flags) && (version_compare(PHP_VERSION, '5.2.11', '<') || version_compare(PHP_VERSION, '5.3.0', '='))) { + $https_flags = STREAM_CLIENT_CONNECT; + } + else { + $https_flags = STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT; + } + $flags = $https_flags; + } + if (empty($options['context'])) { - $fp = @stream_socket_client($socket, $errno, $errstr, $options['timeout'], STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT); + $fp = @stream_socket_client($socket, $errno, $errstr, $options['timeout'], $flags); } else { // Create a stream with context. Allows verification of a SSL certificate. - $fp = @stream_socket_client($socket, $errno, $errstr, $options['timeout'], STREAM_CLIENT_ASYNC_CONNECT|STREAM_CLIENT_CONNECT, $options['context']); + $fp = @stream_socket_client($socket, $errno, $errstr, $options['timeout'], $flags, $options['context']); } // Make sure the socket opened properly.