php - PHP 是否从我使用 opcache.opcache_compile_file() 编译的文件中的包含执行文件?
问题描述
[PHP 文档opcache.opcache_compile_file
说:
此函数编译 PHP 脚本并将其添加到操作码缓存中而不执行它。
如果我使用 编译一个文件opcache_compile_file()
,并且该文件包含其他文件(通过include()
、require()
等),是否会执行包含的文件?或者包含的文件是否会被编译并添加到 opcache 中?
编辑
从评论中提出的观点来看,包含的文件是否也添加到了缓存中?还是opcache_compile_file()
只是忽略包含(也许是最佳行为)?
解决方案
有同样的问题,我用谷歌搜索,我通过在 xampp 中与 stackoverflow 研究员打开 opcache 得到了一些结果
所以我做了我成功的愚蠢测试..
在 php.ini 我把这些
[opcache]
zend_extension=C:\xampp\php\ext\php_opcache.dll
opcache.enable=1
opcache.enable_cli=1
所以在 htdocs\stupidtest* index.php * 我把这个:
<?php
opcache_compile_file('test.php');
test();
在 test.php我放
<?php
function test(){
echo 'yep';
}
和另一个名为the_answer_i_need.php 的文件
<?php
include('test.php');
print_r(opcache_is_script_cached('test.php'));
test();
?>
现在让我们玩游戏:在我的情况下首先运行 index.php http://localhost/test/index.php
然后我运行 the_answer_i_need.php http://localhost/test/the_answer_i_need.php 在我的情况下
我得到的结果是 1yep
1 means boolean true
'yep' means the function called are included from cache cause the previous result was **true**
*job done,we're good*
自 2002 年以来,我编写了世界上最快的 php 框架,这个技巧将允许我将框架核心的某些部分切换为 php 之后的第二个预处理器,并获得大约 40% 的速度。
推荐阅读
- web-services - 寻址服务时使用什么 HTTP 请求方法?
- sqlite - 外键约束在 SQlite 中不起作用
- sql - 与上年的百分比差异
- c# - 从 DialogContext 获取 TurnState 数据
- python - 将列表成员传递给python函数中的一个变量
- networking - 如何为 Kubernetes 配置这个外部服务?
- dart - 如何在 Flutter 中使用 TextField 中的 onKeyUp 事件
- google-chrome - chrome 扩展 storage.get 无法设置默认值
- jsonschema - 使用 oneOf 的 JSON 模式数组验证问题
- internet-explorer - 左括号在 Internet Explorer DevTools 中不起作用