Opcode caching in APC and missing files

We use APC as the operation cache code. Is there a way to force APC to cache file non-existence? We installed apc.stat = 0and apc.include_once_override = 1. Is there anything else to improve call performance include_oncein a file that might not be on the file system? If it is present, we obviously want to enable it. However, if it is not there, it will never be present, and we do not want PHP to call open()the file on every request to check.

For some background: we have one base site, but it provides settings for the site on a "client-client" basis. Some clients have a custom login page, others have unique pages, etc.

We use the Zend Framework in a somewhat unusual way to allow us to redefine controllers as needed. There may be a controller on our site called under the name LoginControllerdefined in the file controllers/LoginController.php. However, our “Company” client may have a requirement for a custom login page, so we will write a new class called Company_LoginControllerin the directory controllers/company/LoginController.php. (This naming convention allows us to conform to the concept of “modules” of the Zend Framework.)

When we deal with a class, we basically do something like this:

include_once APPLICATION_PATH . '/controllers/company/LoginController.php';
if (class_exists("Company_LoginController")) {
    echo 'customer-specific controller exists';
} else {
    include_once APPLICATION_PATH . '/controllers/LoginController.php';
    echo 'customer-specific controller does not exist; using default';
}

/controllers/company/LoginController.php , APC . , /controllers/company/LoginController.php , , APC . ?

+3
3

? APC , , "" .

+3

jmucchiello , - , - .

, , , APC

function conditional_include($file) {
  $key = 'file-exists-' . $file;
  //fetch cache key; if it does not exist, then...
  if(($fileExists = apc_fetch($key)) === false) {
    //actually hit the disk to look for the file, and store the result
    apc_store($key, $fileExists = (file_exists($file) ? 1 : 0));
  }

  //only include the file if it exists.
  if($fileExists)
   include_once $file;
}
+2

If you are using the Zend Framework, I would recommend using Zend_Loader boot magic to make sure the downloaded files are uploaded. Using the autoloader, you can cut almost all include_once calls from ZF (except for those specified in the Zend_Loader class) Caveat - depends on your class and file name style, but you can rewrite / extend the autoloader to counter this.

It may not be like you, but I hope it will be useful nonetheless.

0
source

Source: https://habr.com/ru/post/1708223/


All Articles