Skip to content

PHP 8.2 — Remove conditional memory_reset_peak_usage() call #47

@s2x

Description

@s2x

PHP 8.2 — Remove conditional memory_reset_peak_usage() call

Problem Description

In the file src/Http/HttpRequestHandler.php there is a conditional call to the memory_reset_peak_usage() function, which checks the PHP version before calling it:

if (PHP_VERSION_ID >= 80200) {
    \memory_reset_peak_usage();
}

Since the project is dropping support for PHP 8.1 and now requires PHP 8.2+, this condition is unnecessary and can be removed.

Location

  • /home/decodo/work/workerman-bundle/src/Http/HttpRequestHandler.php lines 49-51

Analysis

Current code (lines 47-51):

public function __invoke(TcpConnection $connection, Request $request): void
{
    if (PHP_VERSION_ID >= 80200) {
        \memory_reset_peak_usage();
    }
    // ...
}

The memory_reset_peak_usage() function was introduced in PHP 8.2 and is used to reset peak memory usage. The condition PHP_VERSION_ID >= 80200 was necessary when the project supported PHP 8.1, but is now redundant.

Proposed Solution

Remove the if condition and call the function directly:

public function __invoke(TcpConnection $connection, Request $request): void
{
    \memory_reset_peak_usage();
    // ...
}

Change:

  • Remove lines 49-51 (the if block)
  • Leave only the call \memory_reset_peak_usage(); on line 49

Priority

🔵 MINOR — code cleanup. This change does not affect functionality, but simplifies the code and removes an unnecessary condition that will always be satisfied in the new PHP 8.2+ environment.

Tests

After making changes:

  1. Run vendor/bin/phpunit to ensure the HTTP handler works correctly
  2. Check if there are any memory-related errors in the logs
  3. Verify operation during HTTP request handling

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-qualityCode quality improvementsminorMinor priority - code quality

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions