WordPress.org

Make WordPress Core

Changeset 12424


Ignore:
Timestamp:
12/17/2009 04:13:58 PM (8 years ago)
Author:
ryan
Message:

Properly handle float timeouts for all transports. Props mdawaffe. fixes #11468

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/http.php

    r12367 r12424  
    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.
     
    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'] ) {
     
    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'] ) {
     
    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'],
     
    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
     
    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 );
     
    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
Note: See TracChangeset for help on using the changeset viewer.