Make WordPress Core

Ticket #13841: 13841.7.diff

File 13841.7.diff, 1.6 KB (added by kirasong, 13 years ago)

Closes file handles and unsets variables appropriately before returning the timeout error.

  • wp-includes/class-http.php

     
    697697                        if ( ! $stream_handle )
    698698                                return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) );
    699699
    700                         while ( ! feof($handle) ) {
     700                        while ( ! feof( $handle ) ) {
     701                                $info = stream_get_meta_data( $handle );
     702
     703                                if ( $info['timed_out'] ) {
     704                                        unset( $strResponse );
     705                                        fclose( $stream_handle );
     706                                        return new WP_Error( 'http_request_failed', __( 'Request timed out.' ) );
     707                                }
     708
    701709                                $block = fread( $handle, 4096 );
    702710                                if ( $bodyStarted ) {
    703711                                        fwrite( $stream_handle, $block );
     
    716724                        fclose( $stream_handle );
    717725
    718726                } else {
    719                         while ( ! feof($handle) )
     727                        while ( ! feof( $handle ) ) {
     728                                $info = stream_get_meta_data( $handle );
     729
     730                                if ( $info['timed_out'] ) {
     731                                        unset( $strResponse );
     732                                        fclose( $handle );
     733                                        return new WP_Error( 'http_request_failed', __( 'Request timed out.' ) );
     734                                }
     735
    720736                                $strResponse .= fread( $handle, 4096 );
     737                        }
    721738
    722739                        $process = WP_Http::processResponse( $strResponse );
    723740                        unset( $strResponse );
     
    869886                if ( ! empty($r['body'] ) )
    870887                        $arrContext['http']['content'] = $r['body'];
    871888
     889                // timeouts with stream_context_create for some reason need to be half of what you expect
     890                $arrContext['http']['timeout'] = $r['timeout'] / 2;
     891
    872892                $context = stream_context_create($arrContext);
    873893
    874894                if ( !WP_DEBUG )