Compressing a string
Compress content: gzcompress()
If you have some content in string format you can try to save space (in terms of bytes) compressing it.
For example, after performing serializing array or a big object you may want to compress the string obtained to save space.
Letβs try to do this:
- define an array,
- serialize the array into a string
- compress the string
After serializing and after compressing you could check the size of the string, and you will see that you can save 50% of the space.
You can set the level of compression, from 0 to 9. 0 means no compression, 9 means maximum compression (slower), the default is 6.