Title: WP_Http_Encoding::compatible_gzinflate
Published: April 25, 2014
Last modified: February 24, 2026

---

# WP_Http_Encoding::compatible_gzinflate( string $gz_data ): string|false

## In this article

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

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

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

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

Certain Servers will return deflated data with headers which PHP’s gzinflate() function
cannot handle out of the box. The following function has been created from various
snippets on the gzinflate() PHP documentation.

Warning: Magic numbers within. Due to the potential different formats that the compressed
data may be returned in, some “magic offsets” are needed to ensure proper decompression
takes place. For a simple pragmatic way to determine the magic offset in use, see:
[https://core.trac.wordpress.org/ticket/18273](https://core.trac.wordpress.org/ticket/18273)

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

 `$gz_data`stringrequired

String to decompress.

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

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

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

    ```php
    public static function compatible_gzinflate( $gz_data ) {

    	// Compressed data might contain a full header, if so strip it for gzinflate().
    	if ( str_starts_with( $gz_data, "\x1f\x8b\x08" ) ) {
    		$i   = 10;
    		$flg = ord( substr( $gz_data, 3, 1 ) );
    		if ( $flg > 0 ) {
    			if ( $flg & 4 ) {
    				list($xlen) = unpack( 'v', substr( $gz_data, $i, 2 ) );
    				$i          = $i + 2 + $xlen;
    			}
    			if ( $flg & 8 ) {
    				$i = strpos( $gz_data, "\0", $i ) + 1;
    			}
    			if ( $flg & 16 ) {
    				$i = strpos( $gz_data, "\0", $i ) + 1;
    			}
    			if ( $flg & 2 ) {
    				$i = $i + 2;
    			}
    		}
    		$decompressed = @gzinflate( substr( $gz_data, $i, -8 ) );
    		if ( false !== $decompressed ) {
    			return $decompressed;
    		}
    	}

    	// Compressed data from java.util.zip.Deflater amongst others.
    	$decompressed = @gzinflate( substr( $gz_data, 2 ) );
    	if ( false !== $decompressed ) {
    		return $decompressed;
    	}

    	return false;
    }
    ```

[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/6.9.4/src/wp-includes/class-wp-http-encoding.php#L104)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-http-encoding.php#L104-L138)

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

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

Decompression of deflated string.

  |

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

| Version | Description | 
| [2.8.1](https://developer.wordpress.org/reference/since/2.8.1/) | 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%2Fcompatible_gzinflate%2F)
before being able to contribute a note or feedback.