require, require_once, etc.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I read on a website recently that using require_once, although it
sounds like a nice idea, actually is processor expensive. But the guy
who posted that didn't say what else is faster:

* require
* include
* include_once

Which is fastest?

Re: require, require_once, etc.

Roberto wrote:
Quoted text here. Click to load it

Not much difference between any of the three, at least the first time  
the file is included.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: require, require_once, etc.


Quoted text here. Click to load it

Usually you won't notice any difference, if there is one at all in
recent PHP versions.

Quoted text here. Click to load it

Just use what fits your needs the best. If you encounter performance
problems, use a profiler to find the real bottlenecks in your code.


Re: require, require_once, etc.

Quoted text here. Click to load it

You missed out __autoload()

There's not a lot of difference in performance - there is a lot of
difference in the functionality - which should determine which you
use. RTFM

How you use include files in general all rather depends on the scale
of your application in terms of lines of code and traffic volumes.

IME it's not particularly CPU intensive but having a lot of includes
can use up more memory than if the code were inline - but splitting
code into multiple files makes it easier to only load the code you
need (saving memory and CPU) and (unless you are Google, this next one
is typically the decider) makes managing your code much easier.

IIRC there used to be a tool out there which would inline code
automatically - a sort of precompiler. But I suspect it won't handle
all the scenarios that would be resolved by an explicit include or


Site Timeline