如何在应用程序中正确插入 opcache_compile_file?

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;

  }


Smart猫小萌
浏览 238回答 1
1回答

holdtom

你的第一行不见了'。它应该是:$filename = 'toto.php';接下来,opcache_compile_file()它本身只编译和缓存一个 PHP 脚本,但不执行它。见这里。如果您需要实际执行脚本,则必须包含它(例如使用include/include_once或require/ require_once)。要检查 opcache 是否已加载并启用,您可以执行以下操作:if (&nbsp; &nbsp; function_exists('opcache_get_status') &&&nbsp; &nbsp; ($opcache_status = opcache_get_status()) &&&nbsp; &nbsp; $opcache_status['opcache_enabled']) {&nbsp; &nbsp; // opcache is enabled}最后,如果加载了 opcache,它可能已经为您的所有 web 脚本启用,因此您根本不需要手动编译脚本。您可以使用opcache-gui来深入了解您的 opcache 引擎盖下发生的事情。
打开App,查看更多内容
随时随地看视频慕课网APP