Skip to content

PHP 8.1 Failed to set memory limit to ... bytes (Current memory usage is ... bytes) #8116

Closed
@brainfoolong

Description

@brainfoolong

Description

Hi!

We recently upgraded to PHP 8.1 and now we sporadically get this kind of new errors:

Failed to set memory limit to 536870912 bytes (Current memory usage is 870318080 bytes)

The problem is, the memory usage cannot be that high at that moment, because we use ini_set on the very start of the script, where almost nothing happened.

Furthermore, we can call the same page 100x times, the error does not appear, but sometime, it happens. It is impossible to reproduce. It definitely only is on PHP 8.1 - With PHP 8.0 we never had this kind of issues.

I guess that the system has sometimes wrong internal memory usage stats, maybe from another thread on the same system?

Is there something we can do about it, without just error suppressing or try/catch?

We are on Windows Server, with Apache 2.4.52 and PHP 8.1.2 TSx64.

As said above, unfortunately i have no reproducible example, but the code that throw the error is this line
ini_set("memory_limit", "512M");

Edit: Have now a reproducible script at #8116 (comment)

PHP Version

PHP 8.1.2 TSx64

Operating System

Windows Server 2019

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions