dongwuxie7976 2016-05-30 23:52
浏览 50

压缩Firebase中的数据

I have a PHP script that makes a query to a webservice. I want the results of this query to be inserted into a row in a Firebase realtime database. This firebase database is then being monitored for changes by an Android app.

The amount of text per row can often be 800 Kb, so I would like to compress this. Otherwise my app will need to have to download 800 Kb before the OnDataChanged event happens.

What I have done is as follows (in the PHP script)

I accept the 800Kb string form the web service. I then run GZip on it in the PHP script. With the result, I then use Base64_Encode and this is what I insert the result to Firebase.

It seems to work fine, and I seem to get around 90% compression, meaning only 80Kb inserted rather than 800Kb. It is however a "round the houses" way to do this.

Is there a better way to do this? Surely there must be. Is there any way to get Firebase to GZip the string is is sending to my app? After all the app is using the Firebase SDK.

Here is the PHP code that writes to Firebase...

$compressed_gzipjson = gzencode($jsonresponse, 9);

$firebase->set(DEFAULT_PATH . '/' , base64_encode($compressed_gzipjson));

Any advice very welcome indeed.

  • 写回答

1条回答 默认 最新

  • duanqin4238 2016-05-31 01:21
    关注

    That sounds like an incredibly wasteful use of a realtime database. The Firebase Database is a great tool for synchronizing small pieces of structured (JSON) data. It is not an ideal fit for unstructured data and the fact that you're OK gzipping the text means that it's unnecessary to synchronize the structure.

    Why don't you simply store the text in a cheaper file storage mechanism (such as Firebase Storage)? Then store the URL of the file in the Firebase Database and synchronize it to the clients that way.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害