Make WordPress Core

Ticket #13841: 13841.5.diff

File 13841.5.diff, 1.9 KB (added by kirasong, 14 years ago)

Fixed loop to allow fsockopen timeout to check properly

  • wp-includes/class-http.php

     
    697697                                return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) );
    698698
    699699                        while ( ! feof($handle) ) {
     700                                $info = stream_get_meta_data( $handle );
     701                                if ( $info['timed_out'] )
     702                                        return new WP_Error('http_request_failed', __('Request timed out.'));
    700703                                $block = fread( $handle, 4096 );
    701704                                if ( $bodyStarted ) {
    702705                                        fwrite( $stream_handle, $block );
     
    715718                        fclose( $stream_handle );
    716719
    717720                } else {
    718                         while ( ! feof($handle) )
     721                        while ( ! feof($handle) ) {
     722                                $info = stream_get_meta_data( $handle );
     723                                if ( $info['timed_out'] )
     724                                        return new WP_Error('http_request_failed', __('Request timed out.'));
    719725                                $strResponse .= fread( $handle, 4096 );
     726                        }
    720727
    721728                        $process = WP_Http::processResponse( $strResponse );
    722729                        unset( $strResponse );
     
    868875                if ( ! empty($r['body'] ) )
    869876                        $arrContext['http']['content'] = $r['body'];
    870877
     878                // timeouts with stream_context_create for some reason need to be half of what you expect
     879                $arrContext['http']['timeout'] = $r['timeout'] / 2;
     880
    871881                $context = stream_context_create($arrContext);
    872882
    873883                if ( !WP_DEBUG )
     
    915925                else
    916926                        $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
    917927
    918                 // Streams does not provide an error code which we can use to see why the request stream stoped.
     928                // Streams does not provide an error code which we can use to see why the request stream stopped.
    919929                // We can however test to see if a location header is present and return based on that.
    920930                if ( isset($processedHeaders['headers']['location']) && 0 !== $args['_redirection'] )
    921931                        return new WP_Error('http_request_failed', __('Too many redirects.'));