I'm need to check if memory_limit
is at least 64M
in my script installer. This is just part of PHP code that should work, but probably due to this "M" it's not reading properly the value. How to fix this ?
//memory_limit echo "<phpmem>"; if(key_exists('PHP Core', $phpinfo)) { if(key_exists('memory_limit', $phpinfo['PHP Core'])) { $t=explode(".", $phpinfo['PHP Core']['memory_limit']); if($t[0]>=64) $ok=1; else $ok=0; echo "<val>{$phpinfo['PHP Core']['memory_limit']}</val><ok>$ok</ok>"; } else echo "<val></val><ok>0</ok>"; } else echo "<val></val><ok>0</ok>"; echo "</phpmem>\n";
memory_limit = -1. Simply means to "have no memory limit" meaning: let the script use whatever is left over from the operating system and other important processes running.
The PHP memory_limit is the maximum amount of server memory that each PHP script is allowed to consume. Per the PHP documentation: “This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts from eating up all available memory on a server.”
The memory_get_usage function can be used to track the memory usage. The 'malloc' function is not used for every block required, instead a big chunk of system memory is allocated and the environment variable is changed and managed internally. The above mentioned memory usage can be tracked using memory_get_usage().
You should set your PHP memory limit as low as you can while still allowing your site to function normally. 128 MB is a good baseline. That's a decent amount of memory that will take care of most intensive plugins. If you know you're going to need some extra power, 256 MB will cover even the heaviest plugins.
Checking on command line:
php -i | grep "memory_limit"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With