PHP - *快速*序列化/反序列化? [英] PHP - *fast* serialize/unserialize?

查看:68
本文介绍了PHP - *快速*序列化/反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PHP 脚本,它在 二进制搜索树://ip-to-country.webhosting.info/node/view/6" rel="noreferrer">一个相当大的 CSV 文件 (5MB+).这很好,但是读取/解析/索引文件大约需要 3 秒钟.

I have a PHP script that builds a binary search tree over a rather large CSV file (5MB+). This is nice and all, but it takes about 3 seconds to read/parse/index the file.

现在我想我可以使用 serialize()unserialize() 来加快这个过程.当 CSV 文件在此期间没有改变时,再次解析它没有意义.

Now I thought I could use serialize() and unserialize() to quicken the process. When the CSV file has not changed in the meantime, there is no point in parsing it again.

令我震惊的是,我发现在我的索引对象上调用 serialize() 需要 5 秒,并产生一个巨大的 (19MB) 文本文件,而 unserialize() 则难以忍受27 秒读回来.改进看起来有点不同.;-)

To my horror I find that calling serialize() on my index object takes 5 seconds and produces a huge (19MB) text file, whereas unserialize() takes unbearable 27 seconds to read it back. Improvements look a bit different. ;-)

那么 - 有没有更快的机制来在 PHP 中将大对象图存储到磁盘/从磁盘恢复?

So - is there a faster mechanism to store/restore large object graphs to/from disk in PHP?

(澄清:我正在寻找一种显着不到上述 3 秒来完成反序列化工作的东西.)

(To clarify: I'm looking for something that takes significantly less than the aforementioned 3 seconds to do the de-serialization job.)

推荐答案

您的问题的答案似乎是否定的.

It seems that the answer to your question is no.

即使您发现了二进制序列化格式"选项,这很可能会降低您的预期.

Even if you discover a "binary serialization format" option most likely even that would be to slow for what you envisage.

因此,您可能需要考虑使用(正如其他人所提到的)数据库、memcached 或在线网络服务.

So, what you may have to look into using (as others have mentioned) is a database, memcached, or on online web service.

我还想添加以下想法:

  • 缓存请求/响应
  • 您的 PHP 脚本不会关闭,而是成为回答查询的网络服务器
  • 或者,我敢说,更改您当前使用的数据结构和查询方法

这篇关于PHP - *快速*序列化/反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆