Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking memory_limit in PHP

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";  
like image 954
Spacedust Avatar asked Apr 18 '12 11:04

Spacedust


People also ask

What does memory_limit =- 1 mean?

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.

What is memory_limit in PHP INI?

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.”

How do I monitor PHP memory usage?

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().

What is a good PHP memory limit?

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.


1 Answers

Checking on command line:

php -i | grep "memory_limit" 
like image 53
Okan Avatar answered Sep 21 '22 22:09

Okan