YukHub Forums

Date: Monday 18th June 2018 at 02:16 PM
Welcome, Friend
Join Us Login
Stats: 583 members, 1889 topics.
Trending Recent New Posts

2 Ways To Compress Your Website Contents Using Php - Programming - YukHub

YukHub Forum / Science/Technology / Programming / 2 Ways To Compress Your Website Contents Using Php (462 Views)

5 Reasons Why You Should Host Your Website Locally / 4 Easy Ways To Speed Up Your Website / 7 Ways To Stay Single & Super Excited

(Reply) (Down)

2 Ways To Compress Your Website Contents Using Php by Kingvictor(m): 03:49am On 4 Apr 2017
Compressing content usually results in less data being send across the network. This has three benefits:
*.Bandwidth usage decreases - you can serve more visitors before you reach your bandwidth limit
*.Network latency can be reduced because fewer packets will be used to transmit the data. Your application can appear faster to a user - page load times are reduced.
*.compressing files allows you to format your xhtml code for readibility without sacrificing page load times.
There are two methods to using compression in PHP:

Using zlib.output_compression

Your PHP needs to be built with the zlib extension. In your php.ini file set
zlib.output_compression = On
to enable compression. You also need to make sure zlib.output_handler is empty.
You can change the level of compression by using
zlib.output_compression_level = d
where d is a digit from 1 (minimal compression) to 9 (maximum compression). The higher compression levels increase CPU usage, possibly without any significant reduction in content size. Probably best to use a mid range value like 5. Or you can test different values and compare the content compressions. whatsmyip.org/mod_gz ip_test shows you the original and compressed content sizes for any page you submit. It also tells you if your content is compressed - good for checking if your settings are working.
The PHP manual recommends using this method over the next method.
Note: You can only enable zlib.output_compression in your php.ini file, even though the PHP documentation suggests otherwise.

Using ob_start

The disadvantage with zlib is you need access to the php.ini file, if zlib.output_compression is not already enabled (phpinfo() can show you if its enabled). Some ISPs do not give you access to the php.ini file.
You can use PHP's output bufferingto compress your pages. In your scripts, or on the page you want compressed, add the following line
This should be at the very top of your scripts. It needs to be called before any content is send to the browser/client. If you have an include file that you use for all your pages, you might want to put this line at the top of that file.
This will put all output in PHP's output buffer. At the end of the script, the function ob_gzhandler is called. This callback function determines the compression to use ('deflate' or 'gzip';), and compresses the content. The compressed content is then send to the browser/client.

You have seen two methods of compressing content using PHP with very little effort on your part. I have seen page sizes reduced by up to 68% using these methods. Not bad for one line of code!
Please Join Our Forum Today For More Updates, Click here

Dont Forget To Share This Post; By Using The Share Buttons.

You May Also Like
»5 Reasons Why You Should Host Your Website Locally

»4 Easy Ways To Speed Up Your Website

»7 Ways To Stay Single & Super Excited

»Steps On How To Boost Your Blog Pageviews In Quick Ways

»Boost Your Website Traffic With 10 Millions Active Nigerian Email Addresses

Viewing this topic: 0 users and 1 guest(s)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) ... (8) (9) (10)


Send Free SMS     | Invite Your Friends | About Us | Privacy | Contact Us
Advertise With Us

Date: Monday 18th June 2018 at 02:16 PM

© YUKHUB 2017