Skip Navigation

[Resolved] Server crashing due to log error: readdir() expects parameter 1 to be resource

This thread is resolved. Here is a description of the problem and solution.

Problem:

I migrated this website to a new server for testing, and it completely crashed the new server.

Upon looking into the issue, there is a single error flooding the error log, causing it to grow to an obscenely large file size, causing the server to crash.

The error is:

" readdir() expects parameter 1 to be resource, boolean given in /wp-content/themes/mar-theme-child/functions.php"

Solution:

It is a custom PHP codes problem, see solution here:

https://toolset.com/forums/topic/server-crashing-due-to-log-error-readdir-expects-parameter-1-to-be-resource/#post-1178925

Relevant Documentation:

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by MichaelR9215 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1178921

Hello,

I currently have a website up and running. I migrated this website to a new server for testing, and it completely crashed the new server.

Upon looking into the issue, there is a single error flooding the error log, causing it to grow to an obscenely large file size, causing the server to crash.

The error is:

" readdir() expects parameter 1 to be resource, boolean given in /wp-content/themes/mar-theme-child/functions.php"

Within the functions.php file, the code in question is:

/*===== Load custom cells types for Layouts plugin from the /dd-layouts-cells/ directory =====*/

if ( defined('WPDDL_VERSION') && !function_exists( 'include_ddl_layouts' ) ) {

  function include_ddl_layouts( $tpls_dir = '' ) {
    $dir_str = dirname( __FILE__ ) . $tpls_dir;
    $dir     = opendir( $dir_str );
    while ( ( $currentFile = readdir( $dir ) ) !== false ) {
      if ( is_file( $dir_str . $currentFile ) ) {
        include $dir_str . $currentFile;
      }
    }
    closedir( $dir );
  }
  include_ddl_layouts( '/dd-layouts-cells/' );
}

I saw in a post from 2016 that there was some kind of patch at the time:
https://toolset.com/forums/topic/php-warning-readdir-expects-parameter-1-to-be-resource-infinite-loop/

I realize this may be irrelevant almost three years later, but I was hoping there may be something similar happening now?

The theme being used is a custom theme I built. I am using it on other websites on this server, and none of them are having this issue. I have been using the same theme for at least two years with no problems.

Currently, I have no access to the website, as this log file continues to grow and the server can not handle it.

If there is anything else you would need to know, please ask.

I hope I have given you enough information to start.

I look forward to your reply.

#1178925

Hello,

It is a custom PHP codes problem, according to PHP document:
hidden link
the first parameter "dir_handle" should be a valid PHP "resource", it seems there is some problem in the above line of your PHP codes:

$dir     = opendir( $dir_str );

It failed to provide a valid source, but returns boolean value "False", and conducts the problem:
hidden link
Returns ... FALSE on failure.

I suggest you debug your PHP codes manually these:
1) make sure var "$dir_str" path is correct, existed in your website
2) Make sure nginx/apache can access to that folder, for example
hidden link

#1179327

Your suggestion pointed me in the right direction. I used a migration tool provided by my server company to move this website to the new server. During that process, it seems that a number of empty directories were deleted by the tool because they were empty. However, this function was looking for the empty directory ... there is a version of this function here for your reference:
https://toolset.com/documentation/programmer-reference/layouts-cells-api/#load-cell-template-files

Once I added those folders back, the error log stopped growing.

Thanks!