-
-
Save dgrammatiko/cb111e241f705a8d10565ec14f2c2050 to your computer and use it in GitHub Desktop.
Demo of PHP Preload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "myclass.php required".PHP_EOL; | |
class MyClass | |
{ | |
public function MyFunction():void | |
{ | |
echo "This is a function!".PHP_EOL; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Start of myfile.php".PHP_EOL; | |
echo "Opcache is ".(opcache_get_status()?"on, files will be cached":"off, files will not be cached").PHP_EOL; | |
spl_autoload_register(function(){ | |
echo "Calling autoloader".PHP_EOL; | |
require_once "myclass.php"; | |
}); | |
$thing=new MyClass(); | |
$thing->MyFunction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nothing: | |
Start of myfile.php | |
Opcache is off, files will not be cached | |
Calling autoloader | |
myclass.php required | |
This is a function! | |
opcache: | |
Start of myfile.php | |
Opcache is on, files will be cached | |
Calling autoloader | |
myclass.php required | |
This is a function! | |
preload: | |
myclass.php required | |
Start of myfile.php | |
Opcache is on, files will be cached | |
This is a function! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[opcache] | |
; Still need to enable extension so we don't get error | |
zend_extension=opcache.so | |
opcache.enable=0 | |
opcache.enable_cli=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[opcache] | |
opcache.enable=1 | |
zend_extension=opcache.so | |
opcache.enable_cli=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[opcache] | |
opcache.enable=1 | |
zend_extension=opcache.so | |
opcache.enable_cli=1 | |
opcache.preload=myclass.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$configs=["nothing","opcache","preload"]; | |
foreach($configs as $config) | |
{ | |
echo "$config:".PHP_EOL; | |
passthru("php -c php-$config.ini myfile.php"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment