Home > Back-end >  PHP memory limit detection
PHP memory limit detection

Time:01-05

My questions is how I can detect real memory limit on hosting? The php.ini settings do not always represent the true limits, for example, memory_limit of 512MB, the script might fail at 128MB, same for max_execution time.

CodePudding user response:

you can not check the memory limit of the server using php you can just check the limit which is set by the server admin in php.ini file

CodePudding user response:

If PHP exec commands are not blocked you could run a shell command like

$freeram_r = explode("\n", shell_exec("/usr/bin/free"));

and parse the result. Or directly for the parameter of your choice, e.g. get the real Gigabytes available from the /proc/meminfo output like

$available = shell_exec('awk \'/MemAvailable/ { printf "%.3f \n", $2/1024/1024 }\' /proc/meminfo');
  • Related