Title: WP_Http_Encoding::decompress
Published: April 25, 2014
Last modified: August 20, 2026

---

# WP_Http_Encoding::decompress( string $compressed, int $length = null ): string|false

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#wp--skip-link--target)

Decompression of deflated string.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#description)󠁿

Will attempt to decompress using the RFC 1950 standard, and if that fails then the
RFC 1951 standard deflate will be attempted. Finally, the RFC 1952 standard gzip
decode will be attempted. If all fail, then the original compressed string will 
be returned.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#parameters)󠁿

 `$compressed`stringrequired

String to decompress.

`$length`intoptional

The optional length of the compressed data.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#return)󠁿

 string|false Decompressed string on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#source)󠁿

    ```php
    public static function decompress( $compressed, $length = null ) {

    	if ( empty( $compressed ) ) {
    		return $compressed;
    	}

    	$decompressed = @gzinflate( $compressed );
    	if ( false !== $decompressed ) {
    		return $decompressed;
    	}

    	$decompressed = self::compatible_gzinflate( $compressed );
    	if ( false !== $decompressed ) {
    		return $decompressed;
    	}

    	$decompressed = @gzuncompress( $compressed );
    	if ( false !== $decompressed ) {
    		return $decompressed;
    	}

    	if ( function_exists( 'gzdecode' ) ) {
    		$decompressed = @gzdecode( $compressed );

    		if ( false !== $decompressed ) {
    			return $decompressed;
    		}
    	}

    	return $compressed;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-http-encoding.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-http-encoding.php#L51)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-http-encoding.php#L51-L81)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Http_Encoding::compatible_gzinflate()](https://developer.wordpress.org/reference/classes/wp_http_encoding/compatible_gzinflate/)`wp-includes/class-wp-http-encoding.php` |

Decompression of deflated string while staying compatible with the majority of servers.

  |

| Used by | Description | 
| [WP_Http_Curl::request()](https://developer.wordpress.org/reference/classes/wp_http_curl/request/)`wp-includes/class-wp-http-curl.php` |

Send a HTTP request to a URI using cURL extension.

  | 
| [WP_Http_Streams::request()](https://developer.wordpress.org/reference/classes/wp_http_streams/request/)`wp-includes/class-wp-http-streams.php` |

Send a HTTP request to a URI using PHP Streams.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_http_encoding/decompress/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_http_encoding%2Fdecompress%2F)
before being able to contribute a note or feedback.