PHP - 定义常量与使用 config.ini

发布于 2024-08-05 06:58:59 字数 98 浏览 2 评论 0原文

就性能而言,我想知道哪种定义常量/设置的方法更好?

通过像 Zend_Config_Ini 这样的类使用 config.ini 文件或者只是定义一系列 php 常量?

Performance wise, I was wondering which method of defining constants/settings is better?

Using a config.ini file through a class like Zend_Config_Ini or just defining a series of php constants?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

满身野味 2024-08-12 06:58:59

定义 PHP 常量更快。

原因:

  1. 您的应用程序不需要解析常量文件并将其转换为 PHP 变量
  2. 如果不更改,如果您安装了 APC,PHP 常量文件将被字节码缓存
  3. 常量默认是不可更改的,并且比数组或普通旧有更好的性能变量,因为它们的大小和类型永远不会改变。

Defining PHP constants is faster.

Why:

  1. The constant file needs not to be parsed by your application and converted into PHP variables
  2. If not changed the PHP constant file will be bytecode cached if you have APC installed
  3. Constants are per default unchangeble, and have a better perfomance than arrays or plain old variables since their size and type doesn't change , ever.
咆哮 2024-08-12 06:58:59

由于使用 .ini 文件需要调用 parse_ini_file() (从而读取磁盘上的文件)比内联定义常量要慢得多。不过,如果您在单独的 PHP 文件中定义常量并使用 include() ,可能会得到同样的结果。

但是,我通常建议使用 .ini 文件,因为它更易于维护并且使部署更简单。

Since using .ini files requires a call to parse_ini_file() (and thus reads a file on disk) it will be trivially slower than defining constants inline. Though if you define your constants in a seperate PHP file and include() it would probably come to the same thing.

However, I would usually recommend using .ini files because it is more maintainable and makes deployments simpler.

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