Make WordPress Core

Ticket #11468: 11468.diff

File 11468.diff, 3.5 KB (added by mdawaffe, 15 years ago)
  • wp-includes/http.php

     
    678678                if ( false === $handle )
    679679                        return new WP_Error('http_request_failed', $iError . ': ' . $strError);
    680680
    681                 stream_set_timeout($handle, $r['timeout'] );
     681                $timeout = (int) floor( $r['timeout'] );
     682                $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
     683                stream_set_timeout( $handle, $timeout, $utimeout );
    682684
    683685                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field.
    684686                        $requestPath = $url;
     
    834836                if (! $handle)
    835837                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
    836838
    837                 stream_set_timeout($handle, $r['timeout'] );
     839                $timeout = (int) floor( $r['timeout'] );
     840                $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
     841                stream_set_timeout( $handle, $timeout, $utimeout );
    838842
    839843                if ( ! $r['blocking'] ) {
    840844                        fclose($handle);
     
    10071011                if ( ! $handle)
    10081012                        return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
    10091013
    1010                 // WordPress supports PHP 4.3, which has this function. Removed sanity checking for
    1011                 // performance reasons.
    1012                 stream_set_timeout($handle, $r['timeout'] );
     1014                $timeout = (int) floor( $r['timeout'] );
     1015                $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
     1016                stream_set_timeout( $handle, $timeout, $utimeout );
    10131017
    10141018                if ( ! $r['blocking'] ) {
    10151019                        stream_set_blocking($handle, 0);
     
    11411145                elseif ( ! $is_local )
    11421146                        $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
    11431147
     1148                $r['timeout'] = (int) ceil( $r['timeout'] );
     1149
    11441150                $options = array(
    11451151                        'timeout' => $r['timeout'],
    11461152                        'connecttimeout' => $r['timeout'],
     
    12551261                // Construct Cookie: header if any cookies are set.
    12561262                WP_Http::buildCookieHeader( $r );
    12571263
    1258                 // cURL extension will sometimes fail when the timeout is less than 1 as it may round down
    1259                 // to 0, which gives it unlimited timeout.
    1260                 if ( $r['timeout'] > 0 && $r['timeout'] < 1 )
    1261                         $r['timeout'] = 1;
    1262 
    12631264                $handle = curl_init();
    12641265
    12651266                // cURL offers really easy proxy support.
     
    12921293                elseif ( ! $is_local )
    12931294                        $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify);
    12941295
     1296
     1297                // CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers.  Have to use ceil since
     1298                // a value of 0 will allow an ulimited timeout.
     1299                // Use _MS if available.
     1300                if ( defined( 'CURLOPT_TIMEOUT_MS' ) ) {
     1301                        $timeout_ms = (int) ceil( 1000 * $r['timeout'] );
     1302                        curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout_ms );
     1303                        curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout_ms );
     1304                } else {
     1305                        $timeout = (int) ceil( $r['timeout'] );
     1306                        curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
     1307                        curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
     1308                }
     1309
    12951310                curl_setopt( $handle, CURLOPT_URL, $url);
    12961311                curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
    12971312                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, $ssl_verify );
    12981313                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
    12991314                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1300                 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] );
    1301                 curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
    13021315                curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    13031316
    13041317                switch ( $r['method'] ) {