For php flush - how to disable gzip for specific file?

I have a ajax call to somefile.php . i want the php script to do a simple task and than send back data to the user, and only than do very time consuming tasks. so i need to flush the output after the first simple task. it doesn't work, probably because i have gzip enables.

I definitely don't want to disable gzip across all the vhost, and also not in all the folder where somefile.php is. i just want to disable it for this specific file. is that possible?

EDIT:

this is what i've included in my apache conf:

<FilesMatch \.php$>
    SetEnv no-gzip 1
</FilesMatch>

this is my php script:

<?php
$sucesss = @apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);

ob_start();

for($i=0;$i<10;$i++)
{
    echo 'printing...';
    ob_flush();
    flush();

    sleep(1);
}
?>

it doesn't work. i still see all the output together after 10 seconds.

Answers


I was looking for a solutions for the same issue. This is what worked for me but unfortunately it seams NOT to be a VALID header.

<?
header("Content-Encoding: none");
?>

apache_setenv() is correct. See the documentation.

http://php.net/manual/en/function.apache-setenv.php#60530

apache_setenv('no-gzip', '1');

Your problem is that you turned on output buffering with ob_start(). Comment that out.

I've learned that apache_setenv() is only available with the PHP Apache module. It's not available when using FPM. In that case, you have to use .htaccess to turn off GZip. An example is

https://stackoverflow.com/a/36212238/148844

RewriteRule ^dashboard/index - [E=no-gzip:1]
SetEnvIf REDIRECT_no-gzip 1 no-gzip

The - means NOOP, E means set variable, 1 is the value. After redirects, the variables are renamed and prepended with REDIRECT_.

If the output is still being buffered, check if you are going through a proxy or cache. See if headers like Via: 1.1 varnish or Via: 1.1 vegur are present. They will buffer the response also.


Put this in httpd.conf

# exclude certain page requests (e.g. for requesting getMyFile.php?action=getFile&id=3 as non-compressed)
SetEnvIfNoCase Request_URI getMyFile\.php$ no-gzip dont-vary

Need Your Help

Scraping for a "preview" of a webpage - Python

python html django screen-scraping

I'm indexing a list of links, these links update quite often so I'm automating thumbnails for the sites.

Why are events and commands in MVVM so unsupported by WPF / Visual Studio?

wpf events mvvm command

When creating an WPF application with the MVVM pattern, it seems I have to gather the necessary tools myself to even begin the most rudimentary event handling, e.g.