Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

In order to improve the performance on I/O calls, you need to implement the file caching. This can be achieved by installing and enabling OPCache (opcache.enable=1) and tweak its settings (see: How to use PHP OPCache?How to use PHP OPCache?). Using memory-based caching such as memcached/redis is also advised.

In order to improve the performance on I/O calls, you need to implement the file caching. This can be achieved by installing and enabling OPCache (opcache.enable=1) and tweak its settings (see: How to use PHP OPCache?). Using memory-based caching such as memcached/redis is also advised.

In order to improve the performance on I/O calls, you need to implement the file caching. This can be achieved by installing and enabling OPCache (opcache.enable=1) and tweak its settings (see: How to use PHP OPCache?). Using memory-based caching such as memcached/redis is also advised.

added 288 characters in body
Source Link
kenorb
  • 14.3k
  • 10
  • 98
  • 168

Or for caching file_scan_directory calls from drupal_system_listing(), then check the following patch available at: file_scan_directory should be cached.

Or for caching file_scan_directory calls from drupal_system_listing(), then check the following patch available at: file_scan_directory should be cached.

Added patch.
Source Link
kenorb
  • 14.3k
  • 10
  • 98
  • 168

You can further consider optimizing drupal_system_listing() or file_scan_directory() by implementing static cache, e.g.

--- a/includes/file.inc
+++ b/includes/file.inc
@@ -2104,6 +2104,8 @@ function file_download_access($uri) {
  *   'filename', and 'name' members corresponding to the matching files.
  */
 function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
+  static $dirs = array();
+
   // Merge in defaults.
   $options += array(
     'nomask' => '/(\.\.?|CVS)$/',
@@ -2120,7 +2122,12 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
       if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {
         $uri = "$dir/$filename";
         $uri = file_stream_wrapper_uri_normalize($uri);
-        if (is_dir($uri) && $options['recurse']) {
+
+        if (empty($dirs[$uri])) {
+          $dirs[$uri] = is_dir($uri);
+        }
+
+        if ($dirs[$uri] && $options['recurse']) {
           // Give priority to files in this folder by merging them in after any subdirectory files.
           $files = array_merge(file_scan_directory($uri, $mask, $options, $depth + 1), $files);

You can further consider optimizing drupal_system_listing() or file_scan_directory() by implementing static cache, e.g.

--- a/includes/file.inc
+++ b/includes/file.inc
@@ -2104,6 +2104,8 @@ function file_download_access($uri) {
  *   'filename', and 'name' members corresponding to the matching files.
  */
 function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
+  static $dirs = array();
+
   // Merge in defaults.
   $options += array(
     'nomask' => '/(\.\.?|CVS)$/',
@@ -2120,7 +2122,12 @@ function file_scan_directory($dir, $mask, $options = array(), $depth = 0) {
       if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {
         $uri = "$dir/$filename";
         $uri = file_stream_wrapper_uri_normalize($uri);
-        if (is_dir($uri) && $options['recurse']) {
+
+        if (empty($dirs[$uri])) {
+          $dirs[$uri] = is_dir($uri);
+        }
+
+        if ($dirs[$uri] && $options['recurse']) {
           // Give priority to files in this folder by merging them in after any subdirectory files.
           $files = array_merge(file_scan_directory($uri, $mask, $options, $depth + 1), $files);
added 317 characters in body
Source Link
kenorb
  • 14.3k
  • 10
  • 98
  • 168
Loading
Source Link
kenorb
  • 14.3k
  • 10
  • 98
  • 168
Loading