0

I'm using vagrant & virtualbox to create drupal websites on my Windows local machine. My actual drupal website is under a Windows folder, shared with my guest(ubuntu) by using a Windows NFS server (winnfsd).

After playing with NFS mount caching options, I understood that my website becomes really fast when enabling it.(specially files attributes caching with high actimeo parameter)

The website becomes fast, but it's almost unusable to developp at the same time:

  • Changes in my Windows text editor (Sublime Text) are not seen by Linux.
  • Sass/compass/gulp also don't see changes made in Windows if actimeo is superior to few seconds.

And when there is no NFS cache at all, I could see that lots of NFS operations are logged by my NFS server logs. Every Drupal files are accessed even several times to get attributes, nslookup, read, access...

So my idea was to make several NFS mounts, with different NFS caching options.

  • Drupal core files never changed => really long NFS cache
  • Contrib modules changed rarely => really long NFS cache
  • Custom modules change often => NO CACHE
  • My Themes change often => NO CACHE

So here is my question, is it good assumptions ? If yes how do we make those kind of multiple NFS shares ? I thought about Symlinks ? Any one tried this approach ?

5
  • this question appears to be off-topic as it is related to an OS and server side functionality, and not directly to Drupal. You are better off asking this in a different SE site
    – Geoff
    May 31, 2015 at 14:56
  • Cache the code in apc or opcache with it not checking the mtime or md5 of the PHP file
    – mikeytown2
    May 31, 2015 at 16:33
  • @Geoff It's the first time I'm posting a question on this platform. I thought any question related to Drupal development will be accepted. I'm using Drupal for 6 years, but the more we progress with Drupal, the more we need new tools/module to use. And I'm still looking for a fast development environment with lots of tools I need: git, sass/compass, gulp, command line, drush, nginx/apache, php with opcache, xdebug, xhprof, memcache/redis, and so one...
    – heyyo
    May 31, 2015 at 18:26
  • Thanks @mikeytown2 for you answer, unfortunatly it's not enough, I'm already using PHP with opcache in my project. I will check if I'm optimizing md5 and mtime as you recommend. This project(taht I didn't developp) is really heavy, lots of modules, lots of tpl, lots of uploaded files... I have found today an optimization regarding .htaccess and "Override All" settings, it helped quite a bit.
    – heyyo
    May 31, 2015 at 18:27
  • Only questions directly related to Drupal are permitted - questions that could apply to other applications are not appropriate - things like this question about general server setup, regardless of it being a Drupal install could apply to dozens of CMS's and is not appropriate, just as questions on PHP, sql are inappropriate unless they relate to specific Drupal modules and such. The general rule is, if you don't need to know anything about Drupal to answer the question, it doesn't belong here - your question relates to OS specific server settings, not Drupal specifically
    – Geoff
    Jun 1, 2015 at 2:51

1 Answer 1

1
ini_set('opcache.validate_timestamps', FALSE);

Then when you want to push a code change out run

opcache_reset();

or restart the Apache process.

If you're working on a set of files you can use opcache_invalidate() to check if those files need to be recompiled.

// http://stackoverflow.com/questions/24783862/php-recursively-list-all-files-in-directory
function get_dir_contents($dir, &$results = array()){
  $files = scandir($dir);

  foreach($files as $key => $value){
    $path = realpath($dir. DIRECTORY_SEPARATOR. $value);
    if (!is_dir($path)) {
      $results[] = $path;
    }
    elseif (is_dir($path) && $value != "." && $value != "..") {
      get_dir_contents($path, $results);
      $results[] = $path;
    }
  }

  return $results;
}

// https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!OpCodeCache.php/function/OpCodeCache%3A%3Ainvalidate/8
function invalidate_opcodecache($pathname) {
  clearstatcache(TRUE, $pathname);

  // Check if the Zend OPcache is enabled and if so invalidate the file.
  if (function_exists('opcache_invalidate')) {
    opcache_invalidate($pathname, TRUE);
  }
  // If apcu extension is enabled in PHP 5.5 or greater it emulates apc.
  // This is to provide an easy upgrade path if you are using apc's user
  // caching however the emulation does not extend to opcode caching.
  // Therefore we need to check if the function exists as well.
  if (extension_loaded('apc') && function_exists('apc_delete_file')) {
    // apc_delete_file() throws a PHP warning in case the specified file was
    // not compiled yet.
    // @see http://php.net/manual/en/function.apc-delete-file.php
    @apc_delete_file($pathname);
  }
}


$file_path = 'sites/all/modules/custom';
$files = get_dir_contents($file_path);
foreach ($files as $pathname) {
  invalidate_opcodecache($pathname);
}
$file_path = 'sites/all/themes/custom';
$files = get_dir_contents($file_path);
foreach ($files as $pathname) {
  invalidate_opcodecache($pathname);
}

Put this code in your settings.php file.

If using APC the info for that is located here: Best APC settings to reduce page execution time

And apache: Adding .htaccess within httpd.conf correctly

Also see: First page load/execution slow, login slower Drupal 7

1
  • 1
    Thanks a lot @mikeytown2 for your time and this detailed answer. I used your patch "Add static cache to module_load_include()" drupal.org/node/1443308. It already improved greatly the performance. Thanks for sharing the code on invalidation of opcache in settings.php.
    – heyyo
    Jun 2, 2015 at 9:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.