Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable nginx gzip from PHP?

Tags:

php

nginx

gzip

I am tyring to stop nginx from gzipping a single PHP request. I already have the following:

    @ini_set('zlib.output_compression', 'Off');
    @ini_set('implicit_flush', 1);
    header('X-Accel-Buffering: no');

According to everything I have found, that X-Accel-Buffering alone should disable gzip, however when I load this page from a browser, I can still see the header:

Content-Encoding:gzip

I'm using php7-fpm, nginx 1.10.1, debian8

EDIT:

I did a test using sleep() to delay the output. It looks like header('X-Accel-Buffering: no'); IS working, however it only prevents buffering and not gzipping. I guess gzipping is working as a stream somehow.

I can see that if I output 1,000 bytes, looping over an echo statement with 1 char each, the browser receives about 11kb. If i echo a str_rep x 1000, then much less data is sent. There must be some overhead there.

Regardless, I need to disable gzip so that I can send a large amount of content and measure the download time. If it's gzipped, I don't know what the actual throughput is.

like image 779
DAB Avatar asked Dec 11 '16 12:12

DAB


1 Answers

Nginx will not run gzip filter if Content-Encoding header found in answer. So, you can set Content-Encoding: identity header on backend, and nginx will pass it to client without gzip process. identity means "not encoded".

like image 51
Dmitry MiksIr Avatar answered Nov 08 '22 09:11

Dmitry MiksIr