skip to Main Content

So, neither I nor my colleague can find an answer to our question. HOW do we limit PHP’s total memory usage on apache?

We are running CakePHP 2.x on an EC2 instance on AWS, the instance has 15GB of memory. I know that in the php.ini file there is a memory_limit={GB/MB} that according to the PHP docs limits the amount of memory any single script can use. So how do we enable this same type of limit on PHP as a whole? We are running PHP v5.4 on Apache 2.4. Any help would be greatly appreciated!

2

Answers


  1. Ohh i see. You can’t do that with php language. You would have to limit the apache server memory. As well i don’t thats possible. But you can optimize your server cpu usage (number of processes and threads) and use the php.ini memory_limit = 128M which will limit memory usage per process.

    You can edit your confextrahttpd-mpm.conf and manage it:

    # prefork MPM
    
    # StartServers: number of server processes to start
    # MinSpareServers: minimum number of server processes which are kept spare
    # MaxSpareServers: maximum number of server processes which are kept spare
    # MaxRequestWorkers: maximum number of server processes allowed to start
    # MaxConnectionsPerChild: maximum number of connections a server process serves
    
    # before terminating
    <IfModule mpm_prefork_module>
        StartServers             5
        MinSpareServers          5
        MaxSpareServers         10
        MaxRequestWorkers      250
        MaxConnectionsPerChild   0
    </IfModule>
    

    Hope it helps

    Login or Signup to reply.
  2. It depends majorly on you logic, if there is a specific code block where you need to assign more memory to process.
    There are 2 ways.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search