使用 fopen、mysql 查询、include/require 检索字符串值的速度怎么样?

发布于 2024-07-25 16:32:41 字数 258 浏览 5 评论 0原文

这是一个一般性问题。 我需要检索大约 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明天过后 2024-08-01 16:32:41

您没有包含数据集中总共存在多少个这些字符串,以及它们的更新频率。

当只有少数并且很少更新时,使用完全基于 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.

凉墨 2024-08-01 16:32:41

下面哪种方法可以
最快,以便取回
变量?

1)从单独的包含文件中读取

如果是稍微大一点的箱子呢?
例如大约 50 串到 300 串
每个字符?

1)从单独的包含文件中读取

这实际上取决于您对性能而非实用性的重视程度。

Which of the following methods would
be the quickest, in order to retrieve
the variables?

1) reading from a separate include file

And what about a slightly larger case,
e.g. about 50 strings up to 300
characters each?

1) reading from a separate include file

It really depends on how much you value performance over practicality.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文