Why do people say require_once is slower than required?

Possible duplicate:
Why is require_once so bad to use?

When PHP includes a file, I assume that it saves the file name inside the array.

Then, if you include another file, it will check that the array is to see if it is already included, right?

So what's important here? Why are people so afraid of this array check? It is not like you include millions of files ...

In_array checks are performed all the time. I use them in almost all functions :)

+4
source share
3 answers

I'm not sure who the people are who say this, but I think this is one of many optimization myths that permeate any language.

Here is an article that checks the methods: http://arin.me/blog/php-require-vs-include-vs-require_once-vs-include_once-performance-test

Your mileage may vary, but I doubt you will see a significant performance boost by avoiding x_once functions. Use language constructs that are appropriate for the situation and you are not doing anything wrong. x_once may be a sign that you need to review your project organization or consider using an autoloader , but this is not eval ...

+5
source

require_once() has two problems, if you ignore the performance problem, the second is important. If you use require_once() , it means that you can require use the same file more than once. This is essentially an incorrect or erroneous design. Now, part of the performance for a web-optimized application will do nothing. If you understand that serving a static HTML file or cached content is faster than serving a PHP file, you will understand why people say using require_once() is slower.

+2
source

In fact, for a smart planned application, functions like require_once are useless.

For slowness, this is insignificant.

-3
source

All Articles