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
20.97 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 (2votes)
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
A
WordPress Add WordPress images to the RSS feed

By default, if you have enabled the WordPress RSS feed, images will not be included in the RSS f ...

Read More
C
WordPress Customize or Modify the WordPress Post Excerpt

WordPress comes with own functions, such as get_the_excerpt() or the_excerpt(), to output a shor ...

Read More
R
WordPress Remove the URL field in the WordPress comments form

As we know, comments are often misused by website visitors to get external links. Outgoing links ...

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-2023 - 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