Skip to content
Advertisement

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

The [PHP documentation for opcache.opcache_compile_file says:

This function compiles a PHP script and adds it to the opcode cache without executing it.

If I compile a file using opcache_compile_file(), and that file includes other files (via include(), require(), etc.), will the files that are included be executed? Or will the included files just be compiled and added to the opcache?

EDIT

From a point raised in a comment, are the included files also added to the cache? Or does opcache_compile_file() simply ignore includes (maybe the optimal behavior)?

Advertisement

Answer

having the same question ,i googleize and i got some results by turning on opcache in xampp with stackoverflow fellows

so i did my succefull stupid test ..

in php.ini i put these

[opcache]
zend_extension=C:xamppphpextphp_opcache.dll
opcache.enable=1
opcache.enable_cli=1

and so in htdocsstupidtest*index.php* i put this:

<?php
opcache_compile_file('test.php');
test();

in test.php i put

<?php
function test(){
    echo 'yep';
}

and another file called the_answer_i_need.php

<?php
include('test.php');

print_r(opcache_is_script_cached('test.php'));  

test();
?>  

Now let’s play the game: run first index.php http://localhost/test/index.php in my case

then i run the_answer_i_need.php http://localhost/test/the_answer_i_need.php in my case

the result i got is 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* 

i wrote the fastest php framework in the wold since 2002 and this trick will allow me to switch some parts of framework’s core as 2nd pre procesor after the php and to gain around 40% more speed.

9 People found this is helpful
Advertisement