Increasing PHP Memory_Limit. at What Point Does It Become Insane

Increasing PHP memory_limit. At what point does it become insane?

The configuration for the memory_limit of PHP running as an Apache module to server webpages has to take into consideration how many Apache process you can have at the same time on the machine -- see the MaxClients configuration option for Apache.

If MaxClients is 100 and you have 2,000 MB of RAM, a very quick calculation will show that you should not use more than 20 MB *(because 20 MB * 100 clients = 2 GB or RAM, ie the total amount of memory your server has)* for the memory_limit value.

And this is without considering that there are probably other things running on the same server, like MySQL, the system itself, ... And that Apache is probably already using some memory for itself.

Or course, this is also a "worst case scenario", that considers that each PHP page is using the maximum amount of memory it can.


In your case, if you need such a big amount of memory for only one job, I would not increase the memory_limit for PḦP running as an Apache module.

Instead, I would launch that job from command-line (or via a cron job), and specify a higher memory_limit specificaly in this one and only case.

This can be done with the -d option of php, like :

$ php -d memory_limit=1GB temp.php
string(3) "1GB"

Considering, in this case, that temp.php only contains :

var_dump(ini_get('memory_limit'));

In my opinion, this is way safer than increasing the memory_limit for the PHP module for Apache -- and it's what I usually do when I have a large dataset, or some really heavy stuff I cannot optimize or paginate.


If you need to define several values for the PHP CLI execution, you can also tell it to use another configuration file, instead of the default php.ini, with the -c option :

php -c /etc/phpcli.ini temp.php

That way, you have :

  • /etc/php.ini for Apache, with low memory_limit, low max_execution_time, ...
  • and /etc/phpcli.ini for batches run from command-line, with virtually no limit

This ensures your batches will be able to run -- and you'll still have security for your website (memory_limit and max_execution_time being security measures)


Still, if you have the time to optimize your script, you should ; for instance, in that kind of situation where you have to deal with lots of data, pagination is a must-have ;-)

PHP Memory limit not taking effect in normal php scripts

Create a php file called test.php, put inside:

<?php
phpinfo();
?>

Check for "Configuration File (php.ini) Path" and "Loaded Configuration File" to see the correct php.ini path.
Edit php.ini and search for memory_limit and set it to:

memory_limit = 999M

Check if you have more than one occurrency of memory_limit into the php.ini file. In the case, delete it.

Stop apache, and then restart it (apachectl restart | apachectl graceful | kill -1 are not ok. Stop, then start).

Recheck test.php to see if the new parameter got acquired.

Can't increase MAMP php memory limit

Managed to solve it ;-)

The correct one is:

/Applications/MAMP/bin/php/php[your_php_version]/conf/php.ini

find 'memory_limit' and increase the number:

memory_limit = [number]M

Thanks!

Unexpected token and memory limit

I know we've been going back and forth in the comments with some discussion, but thought I'd post an answer since that SyntaxError was really bugging me (I knew it had something to do with AJAX) so I did some quick Google searches.

Yes all the plugins, how many posts you have, etc. will pile up and increase the amount of memory WordPress uses (I wouldn't be concerned unless you need to go above 256MB). The reason the AJAX login was failing with a syntax error is because it was expecting to parse a JSON object (i.e. {"success":false,"error":"User does not exist."}) when in reality it was probably receiving something similar to (since most default Apache configurations have full HTML pages for their standard error messages):

<html>
<head>
<title>500 Internal Server Error</title>
</head>
<body>
Fatal error: Allowed memory size of 44040192 bytes exhausted (tried to allocate 30720 bytes).
</body>
</html>

When trying to parse this as JSON, it obviously failed with a SyntaxError when it hit the first <. Anyways, I don't see it as a problem to raise your memory limit to 64MB or 126MB..

PHP memory limit is not being added osx

I have no experience in using silverstripe CMS, but I found this:
http://www.silverstripe.org/general-questions/show/16355 and http://www.silverstripe.org/installing-silverstripe/show/20228

Maybe it can help you in right direction.

Another clue? (about php.ini)
https://discussions.apple.com/thread/2446810?start=0&tstart=0



Related Topics



Leave a reply



Submit