Efficiency of automatic PHP5 loading

Source: Internet
Author: User
The efficiency of automatic loading of PHP5 is automatically loaded when a class is called. However, when there is no explicit require, the corresponding PHP class file is automatically found in the directory. When I use this class in multiple functions or pages, will I go to the hard disk to find this file every time. Does this increase the hard disk I/O overhead? The efficiency of automatic requ PHP5 loading
Automatic loading is when a class is called. However, when there is no explicit require, the corresponding PHP class file is automatically found in the directory.
When I use this class in multiple functions or pages, will I go to the hard disk to find this file every time. Does this increase the hard disk I/O overhead?
If the explicit require_once statement is used, it is the overhead of one IO. I don't know how to deal with it during project development?

------ Solution --------------------
Yes. when this class is used on multiple pages, will this file be searched on the hard disk every time?
Similarly, when explicitly require_once, the file will be searched for on the hard disk each time.

So there are some extension libraries used to cache these files that are frequently loaded.
------ Solution --------------------
The autoload mechanism makes it possible for PHP programs to automatically include class files when using classes, rather than include all class files at the beginning. this mechanism is also called lazy loading.
When using a class, PHP5 automatically runs the _ autoload () function if it finds that the class is not loaded. in this function, we can load the class to be used.
When using the autoload mechanism, many people's first response is that using autoload will reduce system efficiency, and some people may simply suggest not using autoload for efficiency. After learning about the implementation principle of autoload, we know that the autoload mechanism itself is not a cause that affects system efficiency, and even it may improve system efficiency, because it does not load unnecessary classes into the system ().
So why does autoload reduce system efficiency? In fact, the efficiency of the autoload mechanism is exactly the automatic loading function designed by the user. If it cannot efficiently match the class name with the actual disk file (note that this refers to the actual disk file, not just the file name, the system will have to determine whether a large number of files exist (which needs to be searched in the path contained in each include path), and determine whether a file exists through disk I/O operations, as we all know, the efficiency of disk I/O operations is very low, so this is the efficiency of the autoload mechanism!
Therefore, in system design, we need to define a clear mechanism for ing class names to actual disk files. The simpler and clearer the rule, the more efficient the autoload mechanism is.
Conclusion: the autoload mechanism is not inherently inefficient. it is only by misuse of autoload that a poorly designed automatic loading function can reduce its efficiency.

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.