简体   繁体   English

什么是更快的-使用PEAR包或将所需的库直接包含到php代码中?

[英]What is faster - using PEAR package or including required libraries directly into php code?

What will work faster - using PEAR package or require Some_Library.php files in code? 什么会更快工作-使用PEAR包或在代码中需要Some_Library.php文件?

For example, what is faster - using Smarty as PEAR module or using require_once("Smarty.php")? 例如,什么是更快的-使用Smarty作为PEAR模块或使用require_once(“ Smarty.php”)? Have anyone tested this? 有人测试过吗?

Thank you 谢谢

Both will be loaded from the include paths. 两者都将从include路径加载。 The include path that comes first will be slighty faster, but I highly doubt you will notice a difference. 首先出现的include路径会稍微快一点,但我高度怀疑您会注意到其中的不同。 You could do a benchmark though if you want to have numbers. 如果您想获得数字,则可以进行基准测试。

Basically, it works like this: 基本上,它是这样的:

If you got a copy of Smarty in eg /var/www/app/libs/Smarty and another copy of it in PEAR and your include path is something like include_path="/var/www/app/libs:/php/pear" and you do a require 'Smarty.php', then PHP will first search in libs and immediately find Smarty. 如果您在/ var / www / app / libs / Smarty中获得了Smarty的副本,而在PEAR中获得了Smarty的另一个副本,并且您的包含路径类似于include_path =“ / var / www / app / libs:/ php / pear”并且您需要一个“ Smarty.php”,然后PHP将首先在库中搜索并立即找到Smarty。 But without a local copy, PHP would still search the first include path, before it would search in PEAR, so it's a tiny (microseconds) bit slower. 但是,如果没有本地副本,PHP仍将在PEAR中搜索之前搜索第一个include路径,因此它慢了一点点(微秒)。 Nothing to worry about, unless you got many include paths. 无需担心,除非您有很多包含路径。 And of course, it depends on how you include paths are setup anyway. 当然,这取决于您如何设置路径。 If PEAR comes first, then PHP will always search in there first. 如果PEAR首先出现,那么PHP将始终首先在其中搜索。 And if you use an absolute or relative path in require, the include path will be ignored altogether. 并且,如果在require中使用绝对路径或相对路径,则包含路径将被完全忽略。

See the documentation for include and include_path for further details. 有关更多详细信息,请参见includeinclude_path的文档。

It doesn't matter at all when it comes to performance. 在性能方面根本没有关系。 PEAR does nothing special with the libs. 梨对库没有什么特别的。 In the end they are just included as usual. 最后,它们只是照常包含在内。

PEAR just provides a comfortable way for installation and dependency tracking. PEAR只是提供了一种舒适的安装和依赖项跟踪方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM