
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How To enable GZIP Compression in PHP?
GZIP Compression is a simple, effective way to save bandwidth and speed up PHP application. The mechanism runs behind the GZIP compression is described below −
Step1
The browser/client request for a file to the server.
Step2
The server sends a .zip file to the browser (index.html.zip) rather than plain old index.html in response, due to which the download time and bandwidth decreases.
Step3
After the execution of the above step, the browser downloads the zipped file, extracts it, and then shows it to the user. This loads the webpage very quickly.
In the Apache server, we have to Add the following to .htaccess file to enable GZIP compression.
# compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xmlin AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript # Or, compress certain file types by extension: <files *.html> SetOutputFilter DEFLATE </files>
Note
In PHP files we can enable GZIP compression.
<?php if (substr_count($_SERVER[‘HTTP_ACCEPT_ENCODING’], ‘gzip’)) ob_start(“ob_gzhandler”); else ob_start(); ?>
- Related Articles
- Compression compatible with gzip in Python (zlib)
- Enable MySQL Compression
- How to configure nginx with gzip module for compression on centos 7
- PHP compression Stream Wrappers
- How can I extract or uncompress gzip file using php?
- How to enable or disable interlace using imageinterlace() function in PHP?
- Python Support for gzip files (gzip)
- How to enable Bluetooth in android?
- How to enable wifi in android?
- How to enable JavaScript in Windows?
- How to enable JavaScript in Opera?
- Difference between Lossy Compression and Lossless Compression
- Using gzip and gunzip in Linux
- Program to perform string compression in Python
- How to enable MySQL Query Log?

Advertisements