Hello all,

I have been using require_once() throughout my scripts because I thought it would save the processor time keep looking up the same function include file.

But it seems I might be wrong !

The Manual says

The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being

Does this mean the require_once() is only useful if you use it in the same script more than once ?

I have about 30 different scripts that start like this:

/*
*  a_get_detail.php
*
*
* Connects to tables and extracts the data
*/

require_once("my_functions.php");

other code ....

I have also just read that require_once() is slower than the standard require() function.

In this case is it better for me to be using require() as I don't think I am gaining anything from using require_once(). 😕

Thanks for any advice. 🙂

    Require() include file without checking if this file has been already included. If you include f.e. function libraries more then once, PHP will say that it can't redeclare already declared functions. Require_once() before including a file, checks if this file hasn't been included. Thats why it's slightly slower.

      Require() include file without checking if this file has been already included. If you include f.e. function libraries more then once, PHP will say that it can't redeclare already declared functions. Require_once() before including a file, checks if this file hasn't been included. Thats why it's slightly slower.

      cool,
      but When to use require or require_once()? i see require_once() is faster function in comparison with require, that's right?
      thanks 🙂

        You should use whichever is appropriate for your script, and, unless you have many dozens of files to include, not worry about the time. IOW, let the interpreter do "what the interpreter should do better for you."

          Write a Reply...