function file_included () {
$ vars ['some'] = 'some';
include 'included.php';
}
function file_required () {
$ vars ['some'] = 'some';
require 'included.php';
}
function file_evaled () {
$ vars ['some'] = 'some';
$ content = file_get_contents ('included.php');
eval ('?>'. $ content);
}
function file_tpl_preg () {
$ vars ['some'] = 'some';
$ content = file_get_contents ('included.tpl');
$ content = preg_replace ('# \ {(\ w +) \} #', '<? = $ vars [\' \ 1 \ ']?>', $ content);
eval ('?>'. $ content);
}
function file_tpl_strtr () {
$ vars ['some'] = 'some';
$ content = file_get_contents ('included.tpl');
$ content = strtr ($ content, array (
'{' => '<? $ vars [\ '',
'}' => '\']?> ',
))
eval ('?>'. $ content);
}
function file_tpl_preg_cashe () {
$ file = 'included';
if (filemtime ($ file. '. tpl.php') <filemtime ($ file. '. tpl')) {
$ content = file_get_contents ('included.tpl');
$ content = preg_replace ('# \ {(\ w +) \} #', '<? = $ vars [\' \ 1 \ ']?>', $ content);
file_put_contents ($ file. '. tpl.php', $ content);
}
$ vars ['some'] = 'some';
include $ file. '. tpl.php';
}
function file_tpl_manual_cashe () {
$ file = 'included';
if (! file_exists ($ file. '. tpl1.php')) {
$ content = file_get_contents ('included.tpl');
$ content = preg_replace ('# \ {(\ w +) \} #', '<? = $ vars [\' \ 1 \ ']?>', $ content);
file_put_contents ($ file. '. tpl1.php', $ content);
}
$ vars ['some'] = 'some';
include $ file. '. tpl1.php';
}
| Type of test Time % of speedy | file_included0.00021430100.00% | file_required0.00021500100.33% | file_evaled0.00022488104.94% | file_tpl_preg0.00024208112.96% | file_tpl_strtr0.00022802106.40% | file_tpl_preg_cashe0.00024305113.42% | file_tpl_manual_cashe0.00023100107.79% I will explain the results:
|
|---|
Source: https://habr.com/ru/post/27620/
All Articles