Does PHP (lsphp) have a problem with memory management?

LiteCache

Active Member
#1
To understand what this issue is about, simply run the code below. This code increases the memory by 1 MB with each run, but the script is terminated prematurely and before the max_memory_limit is reached because it is supposedly exceeded. Observed under LSWS/OLS and PHP 8.1.

PHP:
<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('memory_limit', '1024M');

function memory($size) {
    return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2);
}

echo '<strong>max_memory_limit: ' . ini_get('memory_limit') . '</strong><br /><br />';
$memory_usage = [];
for ($i = 0; $i < 1000; $i++) {
    $memory_usage[] = str_repeat(' ', 1024 * 1024);
    echo "RAM Consumption: " . round(memory(memory_get_usage())) . " MiB<br />";
}
RAM Consumption: 1MiB
...
RAM Consumption: 415 MiB
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 1052672 bytes)
 
Top