douguan1887 2010-09-15 22:48
浏览 92
已采纳

存储大型PHP数组,纯PHP或gzip序列化数据?

I have a static large array-of-arrays, witch represents tree structure with about ~100k nodes, this array is only read-only reference for value lockups.

Now, witch of this methods will perform better?

First, simply array definition in pure PHP file, for including in requests

Second, serialize this array, gzip serialized output, and load gzipped file and unserialize for every request

Or convert array to SQLite or somethin' similar, but storage must be capable of fast lockup of long "ID path" ie. 1->5556->123->45->455->Node_name (With actually PHP table doing very good)

Memory limit on server is not a problem

  • 写回答

3条回答 默认 最新

  • duanlei20082008 2010-09-15 22:57
    关注

    You'll need to turn the array into a PHP value a some point anyway, so gzip is out.

    So if you are going to decide between keeping it on disk using something like sqlite, or just let php load it in every time (preferably having APC enabled), the real question is whats more important to you, memory or CPU. If you don't know yet, you're probably suffering from a case of premature optimization.

    When it does become relevant to you to either cut down on memory or cpu, (or io) the answer will be more obvious, so make sure you can easily refactor.

    If you want to predict what's better for you, do a benchmark.

    Update I just saw memory is apparently not a concern. Go for the PHP array and include the file. Easy. Keep in mind though that if the total data size is 10MB, this will be 10MB per apache process. At a 100 apache processes this is already 1GB.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效