繁体   English   中英

PHP 是否从我使用 opcache.opcache_compile_file() 编译的文件中的包含执行文件?

[英]Does PHP execute files from an include in a file I compile with opcache.opcache_compile_file()?

opcache.opcache_compile_file的 [PHP 文档说:

该函数编译一个 PHP 脚本并将其添加到操作码缓存中而不执行它。

如果我使用opcache_compile_file()编译文件,并且该文件包含其他文件(通过include()require()等),是否会执行包含的文件? 或者将包含的文件编译并添加到 opcache 中?

编辑

从评论中提出的观点来看,包含的文件是否也添加到缓存中? 还是opcache_compile_file()只是忽略包含(也许是最佳行为)?

有同样的问题,我在谷歌上搜索,并通过与 stackoverflow 伙伴在 xampp 中打开 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% 的速度。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM