Search code examples
phparraysrequirerequire-once

Why do people say require_once is slower than require?


Possible Duplicate:
Why is require_once so bad to use?

When PHP is including a file I assume it stores the file name inside a array.

Then, when including another file, it will check that array to see if it's already included, right?

So what's the big deal here? Why are people so scared of this array check? It's not like you're including milions of files...

in_array checks are made all the time. I use them in almost all functions :)


Solution

  • I am not certain who the "people" are that say this, but I believe it to be one of many micro-optimization myths that pervade any language.

    Here is an article which benchmarks 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 any significant performance gains by avoiding x_once functions. Use the language constructs that are right for the situation and you aren't doing anything wrong. x_once might be a sign that you need to reconsider your project's organization or consider using autoloader, but it isn't eval...