A Simple Way to Save Bandwidth in PHP

If you were ever looking for a quick and sexy way to save bandwidth on your PHP-based porn high traffic site, all you have to do is add these two lines to the beginning of your PHP scripts:

@ini_set('zlib.output_compression_level', 1);

This will automatically tell the server to compress the PHP page before sending it to the browser. However, sometimes this can causes excess load and a decrease in the speed of your website, but it’s hardly noticable.

Be Sociable, Share!

12 thoughts on “A Simple Way to Save Bandwidth in PHP

  1. High traffic sites should avoid this though. Gzip compression is hard on CPU cycles and increases load under lots of traffic. But you’re correct for lower traffic sites (sub 100k impressions/mo)


  2. This is a good alternative however and said by other people here is that compressing the data before it’s sent to the browser it will suck a lot of server resources on a high demand. There are another alternatives like writing your own code and make use of the filesystem speed. For example if you have a high traffic site you could generate the first page (cover) every N minutes and write the content as a plain html file, then when someone reaches your site they will see a cached page of your first page. I’m not sure if my explanation was good enough but feel free to ask anytime :) thanks for sharing!

  3. Rather than that, you’d probably want to just use a caching module for apache or lighttpd (or whatever http daemon you’re running). Though, that will only help execution time, not bandwidth. Plaintext doesn’t take much space ;)

    If bandwidth saving is the aim, it’s a lot more effective to look at images. First, minimize the number of images on each page to a bare minimum. Do as much as you possibly can with CSS and plain HTML. Then make sure your images are as small as possible without sacrificing quality, and there you’ll see your biggest improvements.

  4. Blocking hotlinkers is a good one as well. I’ve seen a lot of our customers save up to 80% of their bandwidth and half of their memory/CPU usage just by keeping people from linking images from their site. I have a quickie here:


    As for server-side caching, mod_cache with Apache 2.2.x proves to be the best combination for Apache-based servers. If you have a choice though, lighttpd is the top runner

  5. I’ve seen some pretty crazy stuff pulled off with NgineX as well, but I don’t know how compatible it is with everything.

    As for caching plugins with lighttpd, mod_mem_cache is the best for throughput, though if you have a huge site, you’ll need a lot of RAM for that.

  6. If anyone has experience with lighttpd on a cpanel server, one of the resource sites i co-run can use a quickie tutorial on how to install and configure it

  7. It’s pretty useless to compress images and video since they’re already compressed, so the compression ratio is going to be terrible for the CPU cycles that you waste. The plain text content of your site is generally not big enough to even warrant compression. It was a great idea back in the days of 14.4 modems, but with a low B/W connection being 256-512Kb, it’s not so useful.

    A better way to save space is to re-encode all of your images and video with a higher compression ratio, or use a file format that has a better compression ratio.

    Although to sort of defeat my own argument, if you run a mailing list or other such site with alot of plain text content, it might be extremely useful. On the fly gzip compression will still skyrocket your load, but alot of http servers will allow you to have a gzip compressed version of a file and a plain one. This way if the browser sends

    Accept-Encoding: gzip

    It will send the gzipped version automagically. This will save you bandwidth at the cost of diskspace, not CPU cycles, which are more valuable on a high traffic website.

  8. Well we all pretty much agree that using compression is not for high traffic sites (I stated this in the article as well). If you’re on a VPS or dedicated server or you have a low traffic site with just a lot of larger files then compression is more useful. We have a lot of customers that dont get a whole lot of traffic but use a shit ton on bandwidth. If anything, I would recommend caching for high traffic sites, and compression for lower ones.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>