Make WordPress Core

Ticket #13841: 13841.8.diff

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

Close $handle as well.

  • wp-includes/class-http.php

     
    743743                        if ( ! $stream_handle )
    744744                                return new WP_Error( 'http_request_failed', sprintf( __( 'Could not open handle for fopen() to %s' ), $r['filename'] ) );
    745745
    746                         while ( ! feof($handle) ) {
     746                        while ( ! feof( $handle ) ) {
     747                                $info = stream_get_meta_data( $handle );
     748
     749                                if ( $info['timed_out'] ) {
     750                                        unset( $strResponse );
     751                                        fclose( $stream_handle );
     752                                        fclose( $handle );
     753                                        return new WP_Error( 'http_request_failed', __( 'Request timed out.' ) );
     754                                }
     755
    747756                                $block = fread( $handle, 4096 );
    748757                                if ( $bodyStarted ) {
    749758                                        fwrite( $stream_handle, $block );
     
    762771                        fclose( $stream_handle );
    763772
    764773                } else {
    765                         while ( ! feof($handle) )
     774                        while ( ! feof( $handle ) ) {
     775                                $info = stream_get_meta_data( $handle );
     776
     777                                if ( $info['timed_out'] ) {
     778                                        unset( $strResponse );
     779                                        fclose( $handle );
     780                                        return new WP_Error( 'http_request_failed', __( 'Request timed out.' ) );
     781                                }
     782
    766783                                $strResponse .= fread( $handle, 4096 );
     784                        }
    767785
    768786                        $process = WP_Http::processResponse( $strResponse );
    769787                        unset( $strResponse );
     
    915933                if ( ! empty($r['body'] ) )
    916934                        $arrContext['http']['content'] = $r['body'];
    917935
     936                // timeouts with stream_context_create for some reason need to be half of what you expect
     937                $arrContext['http']['timeout'] = $r['timeout'] / 2;
     938
    918939                $context = stream_context_create($arrContext);
    919940
    920941                if ( !WP_DEBUG )