In php, we sometimes use the require () function to introduce multiple files in an initialization file (eg: ini. php. Eg: in ini. {code...} in php ...} then, in a script (eg: example. php), {code ...} but the problem is: In example. in php, we only... in php, we sometimes have an initialization file (eg: ini. use the require () function in php to introduce multiple files.
Eg: in ini. php
require 'a.php';require 'b.php';require 'c.php';require 'd.php';
Then, in a script (eg: example. php ),
require 'ini.php';
But the problem is: In example. in php, we only need to use. php and B. functions in php, instead of c. php and d. php, will this cause php to consume excessive execution time due to the introduction of redundant files during require, thus affecting the efficiency?
Reply content:
In php, we sometimes use the require () function to introduce multiple files in an initialization file (eg: ini. php.
Eg: in ini. php
require 'a.php';require 'b.php';require 'c.php';require 'd.php';
Then, in a script (eg: example. php ),
require 'ini.php';
But the problem is: In example. in php, we only need to use. php and B. functions in php, instead of c. php and d. php, will this cause php to consume excessive execution time due to the introduction of redundant files during require, thus affecting the efficiency?
Introduce unnecessaryc.phpAndd.phpThere will be a certain amount of efficiency loss (the first is the additional read hard disk, the other is to see you in these twophpWhat operations are done in the file-no matter how there is extra loss ).
You canini.phpTo identify the file to be introduced, such:
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];if( stripos($url, 'page1') ){ require 'a.php'; require 'b.php';}else{ require 'c.php'; require 'd.php';}
As we usually useLoaderClass to load the required files,Highlight an On-Demand LoadingFor more information, see:
Autoloader is required. The PHP program should only have a require in the implementation of autoloader, and then there will be a second require in the entrance file to load autoloader at most. The rest of the require are rogue.
Refer to PHP development practices of my radical version
By the way, there is something worse:require_onceIs recommended by the PHP development team to avoid using laruence.