当前位置:网站首页>Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
2022-07-05 13:42:00 【Black hearted green rose】
include() And require() The same function
The only difference :require() Whether executed or not , As long as there is a ,php It will be pre introduced before execution ,include() It is not introduced until the statement is executed
include_once() And require_once() Is to detect whether the file is imported , If it is introduced, it will not be introduced
The only difference : require_once() Unconditionally include , As the name suggests, that is, stop if there is an error after the introduction ,include_once() Then ignore and continue
On efficiency , I want to explain , Please consciously use less include_once()、 require_once()
The principle of this function : The introduction of the file -> Compare whether the current script statement contains -> Decide whether to introduce , Efficiency is conceivable , You think if you have hundreds of class libraries in the whole project , How terrible is it to compare dozens of times in one execution
Here is a solution to prevent the repeated introduction of files in personal multi class libraries :
1. In the calling script, use require();
2. Prevent reuse in class libraries class_exists(‘ Class name ’) or include(‘ Absolute path of class library ’);
explain : The file that calls the script is used once require(), Because the calling script is the general entry of the program , The introduction of public class libraries here rarely results in public class libraries not being used , Use the above statement in the class library , It can prevent the current script from repeatedly introducing the public class library , And only by judging the conditions can the introduction be executed , Pre import will not be repeated , Improve the efficiency of program execution
边栏推荐
- Kotlin协程利用CoroutineContext实现网络请求失败后重试逻辑
- 【Hot100】34. 在排序数组中查找元素的第一个和最后一个位置
- PostgreSQL Usage Summary (PIT)
- MySQL --- 数据库查询 - 排序查询、分页查询
- Address book (linked list implementation)
- Data Lake (VII): Iceberg concept and review what is a data Lake
- Talk about seven ways to realize asynchronous programming
- Aspx simple user login
- Fragmented knowledge management tool memos
- 【MySQL 使用秘籍】一网打尽 MySQL 时间和日期类型与相关操作函数(三)
猜你喜欢
真正的缓存之王,Google Guava 只是弟弟
Could not set property ‘id‘ of ‘class XX‘ with value ‘XX‘ argument type mismatch 解决办法
These 18 websites can make your page background cool
TortoiseSVN使用情形、安装与使用
Huawei push service content, read notes
Wonderful express | Tencent cloud database June issue
How to apply the updated fluent 3.0 to applet development
Summit review | baowanda - an integrated data security protection system driven by compliance and security
Idea set method annotation and class annotation
Can and can FD
随机推荐
运筹说 第68期|2022年最新影响因子正式发布 快看管科领域期刊的变化
Go pointer
What are the private addresses
Don't know these four caching modes, dare you say you understand caching?
Win10——轻量级小工具
今年上半年,通信行业发生了哪些事?
Multi person cooperation project to see how many lines of code each person has written
Flutter draws animation effects of wave movement, curves and line graphs
面试官灵魂拷问:为什么代码规范要求 SQL 语句不要过多的 join?
Redis6 transaction and locking mechanism
百度杯”CTF比赛 2017 二月场,Web:爆破-2
The "Baidu Cup" CTF competition was held in February 2017, Web: explosion-2
Go array and slice
不知道这4种缓存模式,敢说懂缓存吗?
MySQL get time
leetcode 10. Regular expression matching regular expression matching (difficult)
[server data recovery] a case of RAID5 data recovery stored in a brand of server
Clock cycle
leetcode 10. Regular Expression Matching 正则表达式匹配 (困难)
Usage, installation and use of TortoiseSVN