Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the more the better for PHP memory_limit? [closed]

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.

like image 393
夏期劇場 Avatar asked Oct 12 '12 11:10

夏期劇場


People also ask

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.

Should I increase WordPress memory limit?

As WordPress hits the default memory limit, it will try to raise it to 40MB for single-site installations and 64MB for multisite installations. If that isn't enough, a fatal error message line will appear. Unless you installed a plugin that requires more memory, a memory limit of 128MB should suffice for most pages.

How do I increase my memory limit?

To increase the PHP memory limit setting, edit your PHP. ini file. Increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php. ini.

How do I check my PHP memory limit?

The 'memory_limit' is the maximum amount of server memory that a single PHP script is allowed to use. The value needs to be converted before comparing the threshold of memory. For example − 64M is converted to 64 * 1024 * 1024. After this, the comparison is done and the result is printed out.


1 Answers

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.

like image 99
Madara's Ghost Avatar answered Sep 18 '22 18:09

Madara's Ghost