Sanjay Bhalani
Sanjay Bhalani

Reputation: 327

sending large JSON data from android to php server can I compress?

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?

Upvotes: 2

Views: 1988

Answers (4)

Azeem Solangi
Azeem Solangi

Reputation: 1

You can use below for compress json

print_r(gzcompress($data));

Upvotes: -1

Niharika
Niharika

Reputation: 1198

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"

Upvotes: 2

user2861492
user2861492

Reputation:

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));

Upvotes: 3

nitin jain
nitin jain

Reputation: 298

You can use below code

echo gzencode(json_encode($data));

Upvotes: 1

Related Questions