Search code examples
phpperformancememorymemory-limit

Is the more the better for PHP memory_limit?


In PHP, i am oftenly facing memory limit problem. Especially with highly resource integrated systems like Drupal, etc.

What i want to know here is:

  • Is it good to have very high php memory limit like 2GB?
  • Is there any major drawback?

Edited:

As a scenario, for example in Drupal, it NEEDS so much memory while we CLEAR the CACHE via Web Panel (Not by Drush or any script). So even for this case only, i am definitely needing high-limit around 512MB currently.


Solution

  • The golden rule: only give PHP what PHP needs to work, and nothing more.

    This will prevent situations when your system needlessly clogs on the PHP process, and will also assist you in finding bugs (A script that takes 1GB of memory is unusual, and giving a 2GB of memory limit will hide that).


    For exceptional cases, where you know a single script file is very memory heavy, you can use ini_set() to change the memory limit directive at run-time. See this and this.