skip to Main Content

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.

2

Answers


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

    Login or Signup to reply.
  2. 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');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search