SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    194
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    when to compress a string?

    When would you ever want to compress a string with a function like gzcompress() ? Or any other of PHP's compression methods?

    Other than to conserve database space, in what situation is it desirable to compress a string?

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Never contemplate it anymore Don't know why you would even think of it unless you have run into a place where you have some HUGE (as in mb size) strings.

    Twenty years ago, this discussion had a place. Nowadays though the price of storage is not much of a factor so why worry about space?

  3. #3
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ginerjm View Post
    Twenty years ago, this discussion had a place. Nowadays though the price of storage is not much of a factor so why worry about space?
    This is point of view is narrow - of course, compression makes a lot of sense in certain situations and is used nowadays. Some use cases:

    1. Sending data over network is usually much faster when compressed. Browsers support gzip compression so we can send html, css and js files in a compressed format. For example, you can make a php script that will concatenate all your css or js files, compress them and send in one go to the browser. The speed gains are considerable, especially for people on slow connections. There are also other types of files like logs, etc. that you can compress for download and make the process faster.

    2. For archiving purposes it makes a lot of sense to compress files because they are accessed very rarely and sometimes there can be a lot of them and compression can save lots of space.

    While hard disks are cheap hosting space is not that cheap. If you own your server then you can buy multi-terrabyte disks easily but if you have a hosting plan you are restricted to how much you can use. Then compression makes sense.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •