0

I have a web server apache 2.2 with fastcgi and php 5.3, I have memory limit set to 256MB in php.ini and with php-cgi -i I got 256MB. So the configurations is correct, my process read it without problem. I told this because I read many post in internet, and the problem was bad location of php.ini. In my case I'm sure is correct.

My processes php-cgi 8 plus parent allocate RSS for more of 256MB some process allocate also 700MB without problem. Why?

Which is the scope of memory limit when some processes php-cgi can allocate more of 256MB?

I tried to search for some bug, but I can't find nothing.

My application not use ini_set for override memory_limit parameter. So I'm sure the limit of 256MB should be honored.

0

The PHP memory_limit setting is a virtual memory limit. RSS is a measure of physical memory usage. They have very little to do with each other.

The memory_limit setting sets the amount of virtual memory that a PHP script is permitted to directly allocate. It is not a process limit and it is not a physical memory limit.

  • with top I see also for virtual memory more of 256MB. So can you explain better which limit is memory_limit – Giovanni Nervi Jan 21 '14 at 18:40
  • @GiovanniNervi It's not a virtual memory limit for the process, just for one way the PHP system allocates virtual memory. (See updates.) – David Schwartz Jan 21 '14 at 18:41
  • The documentation in php.net talk about This sets the maximum amount of memory in bytes that a script is allowed to allocate. – Giovanni Nervi Jan 21 '14 at 18:45
  • anyway for limit process memory do I need to use ulimit? php can't help me. – Giovanni Nervi Jan 21 '14 at 18:47
  • 2
    @GiovanniNervi It sounds like you didn't ask the question you actually wanted to ask. If you're having some kind of problem, you should describe it in as much detail as possible. (Much of the physical memory you're seeing the processes use is likely shared.) – David Schwartz Jan 21 '14 at 18:51
0

My processes php-cgi 8 plus parent allocate RSS for more of 256MB some process allocate also 700MB without problem. Why?

You told us you were running fastCGI on your websver - I would therefore expect that you are running PHP via PHP-FPM, not PHP-CGI.

You didn't tell us what Operating System this relates to (a rather important consideration when talking about memory management).

It is not alocating that much memory - it is only mapping that much memory. For a concise explanation of the difference and why it matters you should read this.

David's answer is almost correct - memory_limit is the limit on the amount of memory which can be malloc'ed for the scripts execution environment, the script itself if not in the opcode cache (and the first compilation of the code) along with space allocated for storing PHP variables during execution.

In the case of executing PHP code already in the opcode cache, I don't know if the pages in the opcode cache are counted towards the usage constrained by memory_limit - and it would take a lot of work on the source code of PHP to find out.

I have memory limit set to 256MB in php.ini

This is rather high. Since you don't understand how memory management works, I'm wondering why. Setting the limit too high limits the capacity of your system. PHP's execution will happily fill up the space to memory_limit. When memory is becoming tight, garbage collection kicks in and frees up the space occupied by dead (unreferenced) data. If memory never becomes tight, then garbage collection never happens.

As presented here, this does not appear to be a question about managing information systems in a business environment. You have said in the comments that:

My problem is RSS of process php-cgi is unlimited

But it is limited by php.ini's memory limit. If you don't believe me gor write a script which keeps using up data and you'll see it falls over at some point.

If you really mean to ask about how you plan and manage the capacity of the system then that's a very different question - and you don't attempt to answer it by looking at RSS and VSZ.

process aren't killed by oom-killer, php-cgi begin to use swap and slowdone my system

At last! A proper problem statement!

Why does your system have swap if you don't intend to use it? The link above will give you some help for configuring your system so this does not happen. If this is a multi-tenant system where other applications do require swap then you can split them into VMs or containers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.