The Must Have for WordPress
The Must Have for WordPress
×
  • Home
December 5, 2019
PHP

Compress files with Gzip in PHP

by Martin Jost
No comments
1 min Reading Time
1.86 K Views
5 Score
2 Likes
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp

If you already want to Gzip compress a file with PHP, the following function will help you. This allows you to store a file in advance gzip-compressed.

How does the Gzip function work?

Um mit dieser Funktion zu arbeiten, benötigen wir den absoluten Server-Pfad zu einer Datei, welchen wir innerhalb der Funktion mit create_gzip( "/../htdocs/ordner/meine-datei.js" ); übergeben.

To work with this function, we need the absolute server path to a file, which we pass to the function with create_gzip( "/../htdocs/folder/my-file.js" );.

In addition, the compression level can also be customized. The value “w9” is the highest possible compression level. Please note! Not every browser supports the compression type or compression level of Gzip.

Enable automatic gzip compression in .htaccess

Typically, a web host provides a “.htaccess” file for each website as long as the web server is running with Apache. Within this “.htaccess” file, you can also enable automatic Gzip compression for specific file types.

Enable automatic Gzip compression in the php.ini file

Depending on which hosting provider do you have chosen for creating a website, there is also the possibility to enable automatic Gzip compression in the “php.ini” file.

With zlib compression we can compress php scripts or output from php to speed up the loading time of the web page.

Disable Gzip compression

The following command allows us to disable automatic gzip compression by the server.

Last updated: December 5, 2019

Compress files with Gzip in PHP Score: 5 / 5 (1vote)
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp
The Author
Published by
Martin Jost

View all posts by Martin Jost

Related Posts
G
PHP Get the current WordPress URL

In some cases, it may be necessary to get the current WordPress URL of where the user is current ...

Read More
C
Gutenberg Calculate the correct content width for the Gutenberg editor

The WordPress Gutenberg editor allows you to customize and edit web page content according to th ...

Read More
G
PHP Get Metadata from WordPress Video and Audio files

In addition to images, videos and audio files are other formats that we can upload to WordPress ...

Read More
Read more
T
Previous Post
Trim a PHP string before the last special character
G
Next Post
Get the current WordPress URL
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Imprint
  • Privacy Policy
© 2016-2021 - wphave - The Must Have for WordPress
Login

Lost your password?

RequiredEssential cookies enable basic functions and are necessary for the proper functioning of the website.
  • Name: Cookie Status
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user's web browser allows cookies.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookie_status
  • Duration: 1 Minute
  • Name: Cookie Consent
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user agrees to allow opt-in cookies or not.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookieconsent_analytics, cookieconsent_marketing, cookieconsent_status
  • Duration: 1 Year
  • Name: Like Button
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already gave a like for a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): like_btn_{POST_ID}
  • Duration: 21 Days
  • Name: Post Rating
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already rate a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): rating_{POST_ID}
  • Duration: 7 Days
AnalyticsStatistics cookies collect information anonymously. This information helps us to understand how our visitors use our website.
  • Name: Google Analytics
  • Provider: Google LLC
  • Purpose: Google cookie for website analysis. Generates statistical data on how the visitor uses the website.
  • Privacy Policy: https://policies.google.com/privacy
  • Cookie Name(s): _ga, _gat, _gid
  • Duration: 2 Years