2

i am sending large datasets in JSON format from my android device to my server (using PHP). I want to keep bandwidth costs down. I am wondering: should I gzip compress the JSON data server side before sending the data? is there a javascript gzip uncompression library in php side and what i do in android side?

Sanjay Bhalani
  • 329
  • 1
  • 18
  • following stackoverflow Question may help you
    http://stackoverflow.com/questions/6717165/how-can-i-zip-and-unzip-a-string-using-gzipoutputstream-that-is-compatible-with
    –  Jul 21 '15 at 04:53

4 Answers4

3

You should compress your output JSON, but you can let your php sever side script do it for you. If you use a standard compression on HTTP level the client will decompress that automatically

http://stevehanov.ca/blog/index.php?id=104

If you want to send JSON data single form than use following way

echo gzencode(json_encode($data));
josliber
  • 43,891
  • 12
  • 98
  • 133
2

You can compress your JSON output in this way from PHP server.

echo gzencode(json_encode($data));

And for android side you can use "gzip decoder"

Niharika
  • 1,188
  • 15
  • 37
1

You can use below code

echo gzencode(json_encode($data));
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
nitin jain
  • 298
  • 6
  • 19
  • https://www.google.co.in/search?client=ubuntu&channel=fs&q=android+gzip+decode&ie=utf-8&oe=utf-8&gfe_rd=cr&ei=bHnhVJjPCOTV8geAjoCAAg – nitin jain Feb 16 '15 at 05:01
  • http://stackoverflow.com/questions/6717165/how-can-i-zip-and-unzip-a-string-using-gzipoutputstream-that-is-compatible-with – nitin jain Feb 16 '15 at 05:01
-1

You can use below for compress json

print_r(gzcompress($data));
Sasikumar Murugesan
  • 4,412
  • 10
  • 51
  • 74