Is the more the better for PHP memory_limit?

夏期劇場 picture 夏期劇場 · Oct 12, 2012 · Viewed 36.3k times · Source

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.

Answer

Madara's Ghost picture Madara's Ghost · Oct 12, 2012

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.