4

Some of the pages on our website a hitting the PHP memory limit, which is currently set to 128MB. When requesting to bump the memory limit to 256MB, we were told by the engineer at our hosting company that:

On our server "the average request requires less than 64MB of RAM"

and

"shifting memory limit to 256MB essentially creates an average allocation of 192M of memory that won't get used on most requests"

Is this correct that the memory_limit amount is actually pre-allocated and is 192MB will be wasted for most of our requests?

Thank you!

Invisigoth
  • 121
  • 1
  • 3
  • Do you know exactly why your memory limit has increased? That seems like something that would throw a red flag for me. Good question though +1 – wuno Feb 19 '16 at 05:06
  • Our memory limit has not changed increased, quite honestly we didn't know it was set to 128MB on the production environment until some complaints we received that some admin functions are not working correctly. The hosting company's engineer just told us the above after we requested to bump the memory limit to 256MB. – Invisigoth Feb 19 '16 at 12:47

4 Answers4

6

From: http://php.net/manual/en/ini.core.php#ini.memory-limit

This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

In my experience, many sites require more than 128M.

user2182349
  • 9,569
  • 3
  • 29
  • 41
4

No it does not. It sets the max that a script is allowed to allocate. It doesn't allocate by itself. Test it with the php memory_get_usage function.

source

tokamak
  • 541
  • 3
  • 11
2

No. You can't pre-allocate memory with memory_limit.

See this post as a reference as well: How do I pre-allocate memory for an array in PHP?

Maybe he meant that by bumping the limit to 256M globally, the average request went to 192M. This would mean that there are a lot of people hitting the absurdly low 64M limit.

Community
  • 1
  • 1
Matt
  • 5,315
  • 1
  • 30
  • 57
1

Point on PHP memory limit is "prevent poorly written scripts for eating up all available memory on a server", not "pre-allocate a memory size".

For example from PHP5.6 source It's simply a hard cap that's enforced as needed - or another words "Maximum amount of memory a script may consume".

zend_mm_safe_error(heap, "Allowed memory size of %ld bytes exhausted (tried to allocate %ld bytes)", heap->limit, size);

REF: http://jpauli.github.io/2014/07/02/php-memory.html

Pandaski
  • 140
  • 10