Skip to content

PHP memory leak #1128

Closed
Closed
@adamziel

Description

@adamziel

The issue below was reported by @sejas. It negatively impacts user experience of Playground and wp-now. Let's make sure:

  • PHP has ample memory limit available. Confirm php.ini defaults to, say, 1GB memory.
  • php_wasm.c doesn't contribute to the memory leak problem. PHP itself suffers from one, see pm.max_requests. Is php_wasm.c making it worse?
  • PHP runtime is automatically rotated when an out of memory error is detected AND more than 10 requests were handled to avoid an "infinite rotate trap". This could rely on the error logging API implemented by @bgrgicak.

A few memory leaks were already patched in this repo, find old PRs for more context.

pm.max_requests int
The number of requests each child process should execute before respawning. This can be useful to work around memory leaks in 3rd party libraries. For endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. Default value: 0.


What @sejas reported:

I've created a PHP function to make it much easier to benchmark the memory usage:
I'm currently adding it to the index.php, but you can also try the plugin in Studio or wp-now.

function useAllMemory() {
    echo "Initial memory usage: " . (memory_get_usage()/(1024*1024)) . ' MB <br>';
    // ini_set('memory_limit', '1024MB'); // The php limit seems to be 128MB but it doesn't affect the results.
    $data = '';

    while (true) {
        $data .= str_repeat('a', 1024 * 1024); // Increase string size by 1MB in each iteration
        echo "* " . (memory_get_usage()/(1024*1024)) . ' MB <br>';
    }
}
useAllMemory();
die();

Here are my results:

Observe that the site screenshot displays almost 60MB of maximum memory.
The next (2nd) page load displays 29MB
The third page load 4.4MB
and then 2.4 MB
and 1.3 MB

Screenshot:

315332005-ef2eabc9-ac83-4762-b460-18f3cbd763cd

cc @brandonpayton

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions