tags:

views:

29

answers:

2

Hello,

What will work faster - using PEAR package or require Some_Library.php files in code?

For example, what is faster - using Smarty as PEAR module or using require_once("Smarty.php")? Have anyone tested this?

Thank you

+1  A: 

Both will be loaded from the include paths. The include path that comes first will be slighty faster, but I highly doubt you will notice a difference. 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 e.g. /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. 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. 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. And if you use an absolute or relative path in require, the include path will be ignored altogether.

See the documentation for include and include_path for further details.

Gordon
Thank you for your comment. What can you say about spl_autoload_register and loading PEAR packages? Is it possible? Will spl_autoload_register conflict or no? Thank you.
Kirzilla
@Kirzilla You can very much register an autoload function that includes from PEAR. But I would suggest not to bother too much about these things unless you need them or really run into issues.
Gordon
+1  A: 

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.

Techpriester