PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

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

 August 31, 2022     pear, php     No comments   

Issue

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


Solution

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.



Answered By - Gordon
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,204,396

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing