[英]How to insert crrectly opcache_compile_file inside application?
1 /我不了解缓存,但是我想知道用opcache_compile_file
编写此代码是否正确;
2 /如何检查opcache
退出?
$filename = 'toto.php;
if (is_file($filename)) {
ob_start();
opcache_compile_file($filename);
$new_prods_content .= ob_get_clean();
} else {
echo CLICSHOPPING::getDef('template_does_not_exist') . '<br /> ' . $filename;
exit;
}
你的第一行缺少'
。 它应显示为:
$filename = 'toto.php';
接下来, opcache_compile_file()
本身仅编译并缓存PHP脚本,但不执行该脚本。 看这里 。 如果您需要实际执行脚本,则必须包含它(例如,使用include
/ include_once
或require
/ require_once
)。
要检查是否已加载并启用opcache,您可以执行以下操作:
if (
function_exists('opcache_get_status') &&
($opcache_status = opcache_get_status()) &&
$opcache_status['opcache_enabled']
) {
// opcache is enabled
}
最后,如果已加载opcache,则可能已为所有Web脚本启用了opcache,因此您根本不需要手动编译脚本。 您可以使用opcache-gui来获得一些有关opcache幕后情况的见解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.