2.8.8. memory_limit

The memory_limit parameter specifies the maximum amount of memory that site scripts can use. It helps prevent situations where poorly written scripts consume all of the server's available memory.

The memory_limit value is allocated separately for each running script; therefore, running multiple scripts simultaneously cannot consume the entire memory_limit allocation, but it can consume all of the hosting account's RAM (this can be seen in the charts showing server resource usage). It is important to understand that when a script is launched, the amount of memory allocated under the memory_limit is not "taken" from the RAM. Memory is allocated gradually as it is consumed by each script, but cannot exceed the specified limit; therefore, the notion that running two scripts with a memory_limit of 1024 MB will immediately use 2048 MB is fundamentally incorrect.

It is practically impossible to determine beforehand how much memory or what memory_limit value a site or script will require, since it all depends on the quality of the scripts themselves and the amount of data they process.

If site scripts exceed the available memory limit, the following error may occur: "Fatal error: Allowed memory size of XXX bytes exhausted (tried to allocate YYY bytes)". For a description of this error and possible solutions, see here.
  • Does not affect script performance.
  • The maximum value depends on the plan you are using:
    • On shared hosting: from 512 to 1536 MB.
    • On business hosting — within the RAM limit included in your plan.
  • For the console and cron, the default value is 512 MB. You can set it to the value of one of the sites if you load the site's ini file when running the script.
The value of memory_limit in the site's PHP settings does not affect the default value in the console and cron. To run a script using a console command with the same parameter value as on the site, follow the instruction.
  1. Open the "PHP settings" section of the site for which you need to change the parameter value.
  2. Specify the desired value next to "php_memory_limit" and click "Save" at the bottom of the page:
    • Available values — from 1 MB up to the maximum allowed under your current plan.
    • If you enter 0, the value will be set to the maximum allowed under your current plan after saving.
  3. Wait approximately 10-15 minutes for the changes to take effect.

Attention!

Purchasing extra services such as Memcached, Redis, or OPcache does not increase the memory_limit value.

On a permanent basis:

  • By upgrading to a higher plan.
  • By changing the memory_limit value in the site's PHP settings, if the error message specifies a value less than what is available in your current plan.
Content

    Comments

    gusakovskyi
    Як змітит параметр для phpmyadmin?
    karlov
    Можете пояснити, для чого це потрібно і з якими саме труднощами ви зіткнулися? Як варіант, можете звернутися за консультацією в онлайн-чат.