I see this too – also, there’s a fix that Till Krüss merged today, so guessing we’ll see an update shortly!
The warnings you’re seeing are due to the fact that the variable $item
is not defined properly before it is accessed in the validate_dirlist
method of your plugin. Specifically, the code is trying to access the array offset on a variable that may not have been initialized.
The issue lies in this part of the code in the validate_dirlist
method (around line 211):
if ( $item['type'] === 'f' && strpos( $item, "." ) !== false ) {
return true;
}
The variable $item
is being used without being initialized first. To resolve this, you’ll need to iterate through the $list
array properly and ensure that $item
is defined before trying to access its properties.
Here’s the corrected version of your validate_dirlist
function:
private function validate_dirlist( $list ) {
foreach ( $list as $item ) {
// Ensure $item is defined and is an array
if ( ! isset( $item['type'] ) || ! is_array( $item ) ) {
continue; // Skip invalid or undefined items
}
// check if it's a file and contains a dot (.)
if ( $item['type'] === 'f' && strpos( $item['name'], "." ) !== false ) {
return true;
}
// validate subdirectories recursively
if ( $item['type'] === 'd' && ! empty( $item['files'] ) && is_array( $item['files'] ) ) {
if ( ! $this->validate_dirlist( $item['files'] ) ) {
return false;
}
}
}
return true;
}
Was this ever get patched? I’m still having this error occur quite often and i have the most recent version of the plugin. The error prevents pages from loading and the browser times out. Hopefully Till Krüss can crush this bug.
[error] 374080#374080: *5 FastCGI sent in stderr: “PHP message: PHP Warning: Undefined variable $item in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Trying to access array offset on value of type null in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Undefined variable $item in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211PHP message: PHP Warning: Trying to access array offset on value of type null in /var/www/html/live/wp-content/plugins/nginx-cache/nginx-cache.php on line 211” while reading response header from upstream, request: “GET /wp-admin/tools.php?page=nginx-cache&message=cache-purged HTTP/2.0”, upstream: “fastcgi://unix:/run/php/php8.1-fpm.sock:”
Any word on getting this fix pushed live?
I tried to put in the updated function but it just crashed. Rather just wait till the dev fixes it 🙂
-
This reply was modified 3 months, 2 weeks ago by coldrealms65.
Yep, fixed on GitHub. Will push a release next week.
The proposed change doesn’t work. Specifically, at line 212:
if ( $item[ 'type' ] === 'f' && strpos( $item, "." ) !== false ) {
return true;
}
Given that variable $item is an array,
strpos( $item, "." )
produces an error.
I think that line should read:
if ( $item[ 'type' ] === 'f' && strpos( $item[ 'name' ], "." ) !== false ) {
return true;
}