WordPress.org

Make WordPress Core

Changeset 9572


Ignore:
Timestamp:
11/08/08 22:35:00 (7 years ago)
Author:
ryan
Message:

Prioritize transports differently for non-blocking requests. fixes #8086

File:
1 edited

Legend:

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

    r9188 r9572  
    8585     * @access private 
    8686     * 
     87     * @param array $args Request args, default us an empty array 
    8788     * @return object|null Null if no transports are available, HTTP transport object. 
    8889     */ 
    89     function &_getTransport() { 
    90         static $working_transport; 
     90    function &_getTransport( $args = array() ) { 
     91        static $working_transport, $blocking_transport, $nonblocking_transport; 
    9192 
    9293        if ( is_null($working_transport) ) { 
    93             if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) 
    94                 $working_transport[] = new WP_Http_ExtHttp(); 
    95             else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) 
    96                 $working_transport[] = new WP_Http_Curl(); 
    97             else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) 
    98                 $working_transport[] = new WP_Http_Streams(); 
    99             else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) ) 
    100                 $working_transport[] = new WP_Http_Fopen(); 
    101             else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) 
    102                 $working_transport[] = new WP_Http_Fsockopen(); 
    103         } 
    104  
    105         return $working_transport; 
     94            if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) { 
     95                $working_transport['exthttp'] = new WP_Http_ExtHttp(); 
     96                $blocking_transport[] = &$working_transport['exthttp']; 
     97            } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) { 
     98                $working_transport['curl'] = new WP_Http_Curl(); 
     99                $blocking_transport[] = &$working_transport['curl']; 
     100            } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) { 
     101                $working_transport['streams'] = new WP_Http_Streams(); 
     102                $blocking_transport[] = &$working_transport['streams']; 
     103            } else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) ) { 
     104                $working_transport['fopen'] = new WP_Http_Fopen(); 
     105                $blocking_transport[] = &$working_transport['fopen']; 
     106            } else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) { 
     107                $working_transport['fsockopen'] = new WP_Http_Fsockopen(); 
     108                $blocking_transport[] = &$working_transport['fsockopen']; 
     109            } 
     110 
     111            foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) { 
     112                if ( isset($working_transport[$transport]) ) 
     113                    $nonblocking_transport[] = &$working_transport[$transport]; 
     114            } 
     115        } 
     116 
     117        if ( isset($args['blocking']) && !$args['blocking'] ) 
     118            return $nonblocking_transport; 
     119        else 
     120            return $blocking_transport; 
    106121    } 
    107122 
     
    118133     * @access private 
    119134     * 
     135     * @param array $args Request args, default us an empty array 
    120136     * @return object|null Null if no transports are available, HTTP transport object. 
    121137     */ 
    122     function &_postTransport() { 
    123         static $working_transport; 
     138    function &_postTransport( $args = array() ) { 
     139        static $working_transport, $blocking_transport, $nonblocking_transport; 
    124140 
    125141        if ( is_null($working_transport) ) { 
    126             if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) 
     142            if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) { 
    127143                $working_transport[] = new WP_Http_ExtHttp(); 
    128             else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) 
     144                $blocking_transport[] = &$working_transport['exthttp']; 
     145            } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) { 
    129146                $working_transport[] = new WP_Http_Streams(); 
    130             else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) 
     147                $blocking_transport[] = &$working_transport['streams']; 
     148            } else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) { 
    131149                $working_transport[] = new WP_Http_Fsockopen(); 
    132         } 
    133  
    134         return $working_transport; 
     150                $blocking_transport[] = &$working_transport['fsockopen']; 
     151            } 
     152 
     153            foreach ( array('streams', 'fsockopen', 'exthttp') as $transport ) { 
     154                if ( isset($working_transport[$transport]) ) 
     155                    $nonblocking_transport[] = &$working_transport[$transport]; 
     156            }            
     157        } 
     158 
     159        if ( isset($args['blocking']) && !$args['blocking'] ) 
     160            return $nonblocking_transport; 
     161        else 
     162            return $blocking_transport; 
    135163    } 
    136164 
     
    215243 
    216244        if ( is_null($r['body']) ) { 
    217             $transports = WP_Http::_getTransport(); 
     245            $transports = WP_Http::_getTransport($r); 
    218246        } else { 
    219247            if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { 
     
    223251            } 
    224252 
    225             $transports = WP_Http::_postTransport(); 
     253            $transports = WP_Http::_postTransport($r); 
    226254        } 
    227255 
Note: See TracChangeset for help on using the changeset viewer.