Does the excessive require () in php cause excessive execution time?

Source: Internet
Author: User
Tags autoloader
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.