使用 fopen、mysql 查询、include/require 检索字符串值的速度怎么样?
这是一个一般性问题。 我需要检索大约 20 个字符串(每个字符串大约 100 个字符)的值。 为了检索变量,以下哪种方法最快?
1) 从单独的包含文件中读取,其中变量值被分配(例如 $var1 = "blalablah...."; 等) 2)从文本文件中读取 3) 从(小)数据库读取 - 例如,执行一个简单的 mysql 查询
那么稍微大一点的情况怎么样,例如大约 50 个字符串,每个字符串最多 300 个字符?
谢谢
That´s a general question.
I need do retrieve the value of about 20 strings of about 100 characters each. Which of the following methods would be the quickest, in order to retrieve the variables?
1) reading from a separate include file, where the variables values are assigned (e.g. $var1 = "blablablah...."; etc)
2) reading from a text file
3) reading from a (small) database - e.g. doing a simple mysql query
And what about a slightly larger case, e.g. about 50 strings up to 300 characters each?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有包含数据集中总共存在多少个这些字符串,以及它们的更新频率。
当只有少数并且很少更新时,使用完全基于 PHP 的解决方案或光盘文件解决方案就可以了; 当有 10 亿个数据并且以每分钟数千个的速度更新时,这将成为管理的噩梦。
从最明显(最可维护)的解决方案开始,然后在性能成为问题并且您确定这就是问题的根源时进行优化。
You've not included how many of these strings exist in your data set in total, and how often they're updated.
Using a wholly PHP-based solution or disc-files solution is fine when there are only a few of them and they're rarely updated; it becomes a management nightmare when there are 1bn and they get updated at a rate of thousands per minute.
Start with the most obvious (most maintainable) solution then optimise once performance becomes a problem and you're sure that's the source of it.
1)从单独的包含文件中读取
1)从单独的包含文件中读取
这实际上取决于您对性能而非实用性的重视程度。
1) reading from a separate include file
1) reading from a separate include file
It really depends on how much you value performance over practicality.