my ajax response is very large its actually 900kb. so I need to gzip to improve the performance.
can anyone please help me to get gziped content from my php.
Thanks in advance.
To compress the HTTP request body, you must attach the HTTP header indicating the sending of HTTP request body compressed in gzip format while sending the request message from the Web Service client. Implement the processing for attaching the HTTP header in the client application.
The easiest way to enable GZIP compression on your WordPress site is by using a caching or performance optimization plugin. For example, if you host your WordPress site on Apache web server, W3 Total Cache includes an option to enable GZIP compression under its Browser Cache settings panel.
Gzip is a file format and software application used on Unix and Unix-like systems to compress HTTP content before it's served to a client.
Before outputing anything on the page throw in this:
ob_start("ob_gzhandler");
Then after your content follow it up with:
ob_end_flush();
And your content will be gzipped
Option 1:
configure zlib.output_compression
in your php.ini
Doc: http://www.php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression
Option 2:
Use : ob_gzhandler
Doc: http://php.net/manual/en/function.ob-gzhandler.php
Note:
900Kb
is too much for an ajax response.
If you cannot update your php.ini
config file before using ob_gzhandler()
you could try this too:
ini_set('zlib.output_compression', 1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With