1

i have 2 pages their heads are like this

header:

<?php require_once "database.php"; ?>

page:

<?php require_once "database.php"; 
//some codes; 
require_once "header.php"; ?>

I had to require database again for a script to collect data correctly for a specific page, Would that affect the page performance? Or the _once fixes that?

Calibur Victorious
  • 638
  • 1
  • 6
  • 20
  • 2
    Possible duplicate of [Difference between require, include and require\_once?](http://stackoverflow.com/questions/2418473/difference-between-require-include-and-require-once) – John V. Mar 26 '17 at 18:44

1 Answers1

2

Based on PHP documentation if you had used required_once for a file then it will not be required again. If there is a cost on performance? NO.

The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again.

require_once

  • So there is no problem with what i did in the page? – Calibur Victorious Mar 26 '17 at 18:46
  • @CaliburVictorious no that is the point of `require_once` it does a check. There is a link to the PHP documentation website. In addition even if there is a cost on performance (there is no such problem really) it would be either that or an error thrown in case of using `require`. –  Mar 26 '17 at 18:48