DivisionByZeroError - Problem to access Status Page on PHP 8.1.14

Created on 31 January 2023, almost 2 years ago
Updated 5 September 2024, 4 months ago

Problem/Motivation

The status page is not loading on PHP 8.1. Error:
"PHP message: DivisionByZeroError: Division by zero in ./web/modules/contrib/redis/src/Controller/ReportController.php on line 217 #0 [internal function]: Drupal\redis\Controller\ReportController->overview()

It is happing also on line 219.

Steps to reproduce

Using PHP 8.1 (8.1.14) and Drupal 9.5.2.
Configure Redis using the interface PhpRedis. Try to access the Status page report (/admin/reports/redis).

Proposed resolution

Verify the code to avoid division by zero errors.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇧🇷Brazil adrianopulz Florianópolis

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @adrianopulz
  • 🇧🇷Brazil adrianopulz Florianópolis
  • 🇧🇷Brazil adrianopulz Florianópolis
  • 🇺🇦Ukraine ysamoylenko

    Hello @adrianopulz,

    I faced the same issue after upgrading our environment to PHP 8.1.

    Our Redis instance is on the Azure platform and by simple debugging of $info variable I found that our server does not provide the required properties in the output.

    You can simply check it by changing the code like this

    'value' => $this->t('@read read (@percent_read%), @write written (@percent_write%), @commands commands in @connections connections.', [
    '@read' => json_encode($info),          
    //'@read' => format_size($info['total_net_output_bytes'] ?? $info['Stats']['total_net_output_bytes']),
             // '@percent_read' => round(100 / (($info['total_net_output_bytes'] ?? $info['Stats']['total_net_output_bytes']) + ($info['total_net_input_bytes'] ?? $info['Stats']['total_net_input_bytes'])) * ($info['total_net_output_bytes'] ?? $info['Stats']['total_net_output_bytes'])),
             // '@write' => format_size($info['total_net_input_bytes'] ?? $info['Stats']['total_net_input_bytes']),
             // '@percent_write' => round(100 / (($info['total_net_output_bytes'] ?? $info['Stats']['total_net_output_bytes']) + ($info['total_net_input_bytes'] ?? $info['Stats']['total_net_input_bytes'])) * ($info['total_net_input_bytes'] ?? $info['Stats']['total_net_input_bytes'])),
              //'@commands' => $info['total_commands_processed'] ?? $info['Stats']['total_commands_processed'],
            //  '@connections' => $info['total_connections_received'] ?? $info['Stats']['total_connections_received'],
            ]),

    So, looks like the issue is not related to the PHP version update, maybe just partially when the PHP generates a fatal error after throwing the exception.

    But you can resolve that at least temporarily while you reconfigure your Redis server.

    I've tested several versions of Docker images with Redis and even used Windows ported version but I've not faced the issue experienced on the Azure platform. All tested versions had all the necessary attributes to display.

    Tested locally Redis versions: 3.0.504 - 6.0.14 (Not reproducing)
    Drupal core: 9.4.8
    PHP version: 8.1.14

    Attaching the patch. Hope it will help you.

  • Status changed to Needs review almost 2 years ago
  • 🇺🇦Ukraine ysamoylenko

    Normal info layout in the local environment.

    Temporary fix layout.

  • 🇧🇷Brazil adrianopulz Florianópolis

    Hi @ysamoylenko!

    Yeah, that looks great. I'm using Azure Redis as well.
    The $info needs to be verified before using it to avoid PHP errors.

    Thanks for the patch. =)

  • Status changed to RTBC almost 2 years ago
  • 🇺🇦Ukraine ipinchuk

    Hi guys,

    Thanks for your contribution

    @ysamoylenko, your patch works very well.

    Changed status to RTBC.

  • Status changed to Needs work almost 2 years ago
  • 🇨🇭Switzerland berdir Switzerland
    +++ b/src/Controller/ReportController.php
    @@ -212,14 +212,16 @@ class ReportController extends ControllerBase {
    +        'value' => $info['total_net_output_bytes'] || $info['Stats']['total_net_output_bytes'] ?
    

    are the array keys empty or not set? this will cause php notices if they are not set.

    Lets wrap it in an !empty() to be extra careful.

  • 🇨🇭Switzerland berdir Switzerland

    Also seems to be overlapping/very related to Azure/AWS: Take into account CONFIG command may not work Needs review

  • Status changed to Needs review almost 2 years ago
  • 🇺🇦Ukraine ysamoylenko

    Hello @Berdir,

    Thank you for your response.

    These array keys do not exist in the $info array.

    I am adding a new patch with a non-empty evaluation.

    According to the mentioned issue, it looks similar but for another section of the report.

    In our environment, I have not faced it.

  • 🇫🇷France nicolas bouteille

    it seems patch needs reroll for 1.8

  • 🇺🇦Ukraine oushen

    Patch for 1.8 version

  • Pipeline finished with Success
    4 months ago
    Total: 212s
    #275025
  • 🇫🇷France karimbou

    We are also having this fatal error with PHP8.3.12 and Redis 1.8
    On BO: /admin/reports/redis
    DivisionByZeroError: Division by zero in Drupal\redis\Controller\ReportController->overview() (line 219 of /var/www/html/web/modules/contrib/redis/src/Controller/ReportController.php).

Production build 0.71.5 2024