Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP fatal error with PHP 8.1, repo / Composer installation and WP Rocket's debugging enabled #5918

Closed
4 tasks
vmanthos opened this issue May 11, 2023 · 6 comments · May be fixed by #6279
Closed
4 tasks

PHP fatal error with PHP 8.1, repo / Composer installation and WP Rocket's debugging enabled #5918

vmanthos opened this issue May 11, 2023 · 6 comments · May be fixed by #6279
Assignees
Labels
effort: [XS] < 1 day of estimated development time module: Logger priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior

Comments

@vmanthos
Copy link
Contributor

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version ✔️ 3.13.2
  • Used the search feature to ensure that the bug hasn’t been reported before ✔️

Describe the bug

When:

  1. PHP cli 8.1.* is used & the server is running PHP 8.1.*.
  2. Installing WP Rocket from our repo and running composer install.
  3. WP Rocket's debugging is enabled define( 'WP_ROCKET_DEBUG', true);.

the following PHP Fatal error is logged to the debug.log:

PHP Fatal error:  Uncaught Error: Interface "Psr\Log\LoggerInterface" not found in /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/vendor/monolog/monolog/src/Monolog/Logger.php:34
Stack trace:
#0 /shared/httpd/wprocketest/htdocs/wp-content/advanced-cache.php(51): require()
#1 /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/inc/classes/logger/class-logger.php(187): {closure}('Monolog\\Logger')
#2 /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/inc/classes/logger/class-logger.php(83): WP_Rocket\Logger\Logger::get_logger()
#3 /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/inc/classes/Buffer/class-abstract-buffer.php(120): WP_Rocket\Logger\Logger::info('CACHING PROCESS...', Array)
#4 /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/inc/classes/Buffer/class-cache.php(60): WP_Rocket\Buffer\Abstract_Buffer->log('CACHING PROCESS...', Array, 'info')
#5 /shared/httpd/wprocketest/htdocs/wp-content/advanced-cache.php(75): WP_Rocket\Buffer\Cache->__construct(Object(WP_Rocket\Buffer\Tests), Object(WP_Rocket\Buffer\Config), Array)
#6 /shared/httpd/wprocketest/htdocs/wp-settings.php(95): include('/shared/httpd/w...')
#7 /shared/httpd/wprocketest/htdocs/wp-config.php(137): require_once('/shared/httpd/w...')
#8 /shared/httpd/wprocketest/htdocs/wp-load.php(50): require_once('/shared/httpd/w...')
#9 /shared/httpd/wprocketest/htdocs/wp-blog-header.php(13): require_once('/shared/httpd/w...')
#10 /shared/httpd/wprocketest/htdocs/index.php(17): require('/shared/httpd/w...')
#11 {main}
  thrown in /shared/httpd/wprocketest/htdocs/wp-content/plugins/wp-rocket/vendor/monolog/monolog/src/Monolog/Logger.php on line 34

According to @engahmeds3e:

the problem is coming from the PSR/Log, with php 8.1 they have the following structure:
/vendor/psr/log/src/LoggerInterface.php
https://github.com/php-fig/log/blob/master/src/LoggerInterface.php

but with php 7.4 they have the following structure in v1.1.4
vendor/psr/log/Psr/Log/LoggerInterface.php
https://github.com/php-fig/log/blob/1.1.4/Psr/Log/LoggerInterface.php

So, the problem is coming from our advanced_cache.php file template exactly here:

$file = $rocket_path . 'vendor/psr/log/' . str_replace( '\\', '/', $class ) . '.php';

To Reproduce

The steps are described in the Describe the bug section.

Expected behavior

No PHP fatal error should occur when PHP 8.1.* is used alongside WP Rocket's debugging when the installation was performed using Composer.

Additional context

Slack discussion (internal link)

Backlog Grooming (for WP Media dev team use only)

  • Reproduce the problem
  • Identify the root cause
  • Scope a solution
  • Estimate the effort
@Mai-Saad
Copy link

Duplicated with #5386

@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior module: Logger priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available labels Jun 1, 2023
@Miraeld Miraeld self-assigned this Nov 20, 2023
@Miraeld
Copy link
Contributor

Miraeld commented Nov 20, 2023

Reproduce the problem

To reproduce the issue, follow the step given the problem explanation.

Identify the root cause

The issue is that, as stated in the problem explanation:

the problem is coming from the PSR/Log, with php 8.1 they have the following structure:
/vendor/psr/log/src/LoggerInterface.php
https://github.com/php-fig/log/blob/master/src/LoggerInterface.php

but with php 7.4 they have the following structure in v1.1.4
vendor/psr/log/Psr/Log/LoggerInterface.php
https://github.com/php-fig/log/blob/1.1.4/Psr/Log/LoggerInterface.php

So, the problem is coming from our advanced_cache.php file template exactly here:

$file = $rocket_path . 'vendor/psr/log/' . str_replace( '\\', '/', $class ) . '.php';

Scope a solution

To solve the issue, we could change this line :

$file = $rocket_path . 'vendor/psr/log/' . str_replace( '\\', '/', $class ) . '.php';

to

if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
	$file = $rocket_path . 'vendor/psr/log/src/' . str_replace('\\', '/', $class) . '.php';
} else {
	$file = $rocket_path . 'vendor/psr/log/' . str_replace('\\', '/', $class) . '.php';
}

Development steps:

Effort estimation:

XS

Is a refactor needed in that part of the codebase?

No

@Miraeld Miraeld removed their assignment Nov 20, 2023
@CrochetFeve0251
Copy link
Contributor

@Miraeld The path to the to files is depending on the PSR version and not the PHP version.
I think we should a fallback system for the monolog as we did here:

'WP_Rocket\\Logger\\Logger' => [

@Miraeld Miraeld self-assigned this Nov 20, 2023
@Miraeld
Copy link
Contributor

Miraeld commented Nov 20, 2023

Reproduce the problem

To reproduce the issue, follow the step given the problem explanation.

Identify the root cause

The main issue here is the version of the librairie which changes the path. Depending on the version we need to load a path or another one.

Scope a solution

To fix this issue, we can add

'WP_Rocket\\Dependencies\\Psr\\Log' => [
	$rocket_path . 'inc/Dependencies/Psr/Log/' . str_replace( '\\', '/', $class ) . '.php',
	$rocket_path . 'vendor/psr/log/src/' . str_replace('\\', '/', $class) . '.php',
],

to $rocket_classes here :

$rocket_classes = [

And do not forget to delete

} elseif ( strpos( $class, 'WP_Rocket\\Dependencies\\Psr\\Log\\' ) === 0 ) {

At the same time, we could refactor this one

} elseif ( strpos( $class, 'WP_Rocket\\Dependencies\\Monolog\\' ) === 0 ) {

with the same method.

Development steps:

Effort estimation:

XS

Is a refactor needed in that part of the codebase?

No

@Miraeld Miraeld removed their assignment Nov 20, 2023
@CrochetFeve0251
Copy link
Contributor

Seems good to me

@piotrbak piotrbak added effort: [XS] < 1 day of estimated development time and removed needs: grooming labels Nov 20, 2023
@Miraeld Miraeld self-assigned this Nov 21, 2023
Miraeld added a commit that referenced this issue Nov 21, 2023
@Mai-Saad
Copy link

Mai-Saad commented Nov 27, 2023

The issue isn't reproducible using 3.15.5, Will close it for now. We can reopen it once it happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: [XS] < 1 day of estimated development time module: Logger priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants