The HTTP deflate is quite complicated.
The RFC7230, Sec 4.2.2 (https://tools.ietf.org/html/rfc7230#section-4.2.2) says:
?The "deflate" coding is a "zlib" data format [RFC1950] containing a "deflate" compressed data stream [RFC1951] that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.?
and, also:
?Note: Some non-conformant implementations send the "deflate" compressed data without the zlib wrapper.?
Since this function implements the RFC1951, the compliant encoding of a $payload should be:
gzcompress(gzdeflate($payload));