CRITICAL Uncaught TypeError:

getting CRITICAL Uncaught TypeError: closedir(): Argument #1 ($dir_handle) must be of type resource or null, bool given in /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-admin/includes/file.php:168
Stack trace:

2022-04-28T22:26:02+00:00 CRITICAL Uncaught TypeError: closedir(): Argument #1 ($dir_handle) must be of type resource or null, bool given in /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-admin/includes/file.php:168
Stack trace:
#0 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-admin/includes/file.php(168): closedir()
#1 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-includes/functions.php(6198): list_files()
#2 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-includes/class-wp-hook.php(286): wp_privacy_delete_old_export_files()
#3 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters()
#4 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-includes/plugin.php(515): WP_Hook->do_action()
#5 /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-cron.php(126): do_action_ref_array()
#6 {main}
  thrown in /home/superdarb/domains/doXXXXXssets.XXX/public_html/wp-admin/includes/file.php on line 168

168: 	@closedir( $dir );

6198: 	$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );

286: 	$value = call_user_func_array( $the_['function'], $args );

310: 	$this->apply_filters( '', $args );

515:	$wp_filter[ $tag ]->do_action( $args );

126:  	do_action_ref_array( $hook, $v['args'] );

168: 	@closedir( $dir );

Active plugins (10)

Classic Commerce 	  	by ClassicPress Research Team – 1.0.4
Classic SEO 	  	by ClassicPress – 2.0.1
Head Cleaner 	  	by Simone Fioravanti – 1.2.1
Disable Any Comment 	  	by Gieffe edizioni srl – 1.0.5
Ink Multi Vendor 	  	by InkThemes – 5.0
InkThemes Import Export 	  	by Krish PC – 1.1
LiteSpeed Cache 	  	by LiteSpeed Technologies – 4.6
NinjaFirewall (WP Edition) 	  	by The Ninja Technologies Network – 4.5.1
Ultimate Wordpress Auction Plugin 	  	by Nitesh Singh – 4.1.4
CC Compatibility for Woo Addons 	  	by Classic Commerce Research Team – 9999.1 

PHP: 7.4.29
Classic Commerce version: 1.0.3
ClassicPress Version: 1.4.1

It looks like your site is running on a schedule that is deleting old privacy files when there are none.

The strange thing is that the PHP manual says opendir can return false. It also says for closedir

The stream must have previously been opened by opendir().

But it is coded with @. It seems like more recent versions of PHP changed how @ works, but surely everyone would be getting this error?

There are indeed changes to the @ at least in php :infinity:
Also if some custom handler is set (which is theoretically possible to set server wide) it’d be thrown anyway, as I understand.

@darb are you running php 8 or perhaps setting an error handler?

Does this answer your question:


PHP Version 7.4.29

Directive Local Value Master Value
allow_url_fopen On On
allow_url_include Off Off
arg_separator.input & &
arg_separator.output & &
auto_append_file no value no value
auto_globals_jit On On
auto_prepend_file /home/superdarb/domains/domaXXXXXX.XXX/public_html/wp-content/nfwlog/ninjafirewall.php no value
browscap no value no value
default_charset UTF-8 UTF-8
default_mimetype text/html text/html
disable_classes no value no value
disable_functions exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
display_errors Off Off
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl Off Off
enable_post_data_reading On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 22527 22527
expose_php Off Off
extension_dir /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902 /usr/local/php74/lib/php/extensions/no-debug-non-zts-20190902
file_uploads On On
hard_timeout 2 2
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .:/usr/local/php74/lib/php .:/usr/local/php74/lib/php
input_encoding no value no value
internal_encoding no value no value
log_errors On On
log_errors_max_len 1024 1024
mail.add_x_header On On
mail.force_extra_parameters no value no value
mail.log /home/superdarb/.php/php-mail.log no value
max_execution_time 30 30
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 60 60
max_input_vars 1000 1000
memory_limit 128M 128M
open_basedir /home/superdarb/:/tmp:/var/tmp:/opt/alt/php74/usr/share/pear/:/dev/urandom:/usr/local/lib/php/:/usr/local/php74/lib/php/ no value
output_buffering 4096 4096
output_encoding no value no value
output_handler no value no value
post_max_size 64M 64M
precision 14 14
realpath_cache_size 4096K 4096K
realpath_cache_ttl 120 120
register_argc_argv Off Off
report_memleaks On On
report_zend_debug On On
request_order GP GP
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i -f [email protected] /sbin/sendmail -t -i
serialize_precision -1 -1
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sys_temp_dir no value no value
syslog.facility LOG_USER LOG_USER
syslog.filter no-ctrl no-ctrl
syslog.ident php php
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 64M 64M
upload_tmp_dir no value no value
user_dir no value no value
user_ini.cache_ttl 300 300
user_ini.filename .user.ini .user.ini
variables_order GPCS GPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
zend.assertions -1 -1
zend.detect_unicode On On
zend.enable_gc On On
zend.exception_ignore_args On On
zend.multibyte Off Off
zend.script_encoding no value no value
zend.signal_check Off Off

I am running Ninja Firewall and CIDRAM to protect index.php; perhaps the source of the problem iif I am the only one effected?

I doubt it is the problem.
I’m looking at a code formatting changeset from WP, where the @ was removed, but I can’t tell if that was when the closedir was moved inside the if statement, where it should have always been.
This error likely isn’t hurting your site, since it is a cron run, but it shouldn’t happen either.

It looks like there is a changeset upstream we should backport to fix up some potential PHP8 errors:

As per the recommendation of my web host, I turned off WP-Cron and runs an hourly cron job instead (which is a service provided by my web host). One result of this is that I am sent warning and error messages in email, even about some issues that would normally go unnoticed.

Since yesterday, I started getting the following email every hour, on each one of the CP sites I’m building:

/usr/local/bin/wp cron event run --due-now
--path=/home/public/ --quiet --no-color

completed at 2022-05-30 22:00:47 UTC after 4 seconds and produced the
following output:

Fatal error: Uncaught TypeError: closedir(): Argument #1 ($dir_handle) must
be of type resource or null, bool given in
Stack trace:
#0 /home/public/
#1 /home/public/
list_files('/home/public/ww...', 100, Array)
#2 /home/public/
#3 /home/public/
WP_Hook->apply_filters('', Array)
#4 /home/public/
do_action_ref_array('wp_privacy_dele...', Array)
#7 [internal function]: Cron_Event_Command->run(Array, Array)
call_user_func(Array, Array, Array)
#9 [internal function]:
WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
call_user_func(Object(Closure), Array, Array)
WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
WP_CLI\Runner->run_command(Array, Array)
#15 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(78):
#16 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27):
#17 phar:///usr/local/bin/wp/php/boot-phar.php(11):
#18 /usr/local/bin/wp(4): include('phar:///usr/loc...')
#19 {main}
  thrown in /home/public/ on
line 168
/usr/local/bin/wp cron event run --due-now
--path=/home/public/ --quiet --no-color exited with
return code 255

I performed a recent upgrade to CP version 1.4.1, but based on the timing of the emails I got, this error started before I made the upgrade.

But as far as I can tell, by logging into the site and making a test post, “everything” is working fine.

I just found out that this error has already been reported in this thread:

But perhaps my own report could provide more clarification to the problem.

NOTE: I’m using PHP 7.4, and here is it’s configuration info:

This issue has been fixed in PR #958, which is scheduled for version 1.5.0. This topic will be closed.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.