Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase memory limit for PHP over 2GB?

I have an problem increasing memory limit for PHP as Apache module.

If I put following directive in Apache configuration, that work OK:

php_value memory_limit 1.99G 

But over 2GB do not work, it's restore this value back to 128MB.

What is the problem here? I need more memory for some PDF related tasks.

Server is Debian 2.6.32-5-amd64 #1 SMP, PHP 5.3.3-7+squeeze13 with 12GB physical RAM.

like image 616
mikikg Avatar asked Aug 09 '12 14:08

mikikg


People also ask

How do I increase my PHP memory limit?

To increase the PHP memory limit setting, edit your PHP. ini file. Increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php. ini.

What is the maximum PHP memory limit?

Increasing the PHP memory limit The default memory limit is 256M and this is usually more than sufficient for most needs. If you need to raise this limit, you must create a phprc file.

How much RAM does PHP need?

PHP doesn't free memory during script execution so your memory limit needs to be as high as the most memory one script will consume. If the most a script will ever consume is 2MB then set it to 2MB but if you need 780MB then set it to that. We have large production systems with the memory limit set over 2GB.


2 Answers

Have you tried using the value in MB ?

php_value memory_limit 2048M 

Also try editing this value in php.ini not Apache.

like image 66
Claudiu Claw Avatar answered Sep 19 '22 13:09

Claudiu Claw


I would suggest you are looking at the problem in the wrong light. The questtion should be 'what am i doing that needs 2G memory inside a apache process with Php via apache module and is this tool set best suited for the job?'

Yes you can strap a rocket onto a ford pinto, but it's probably not the right solution.

Regardless, I'll provide the rocket if you really need it... you can add to the top of the script.

ini_set('memory_limit','2048M'); 

This will set it for just the script. You will still need to tell apache to allow that much for a php script (I think).

like image 25
Ray Avatar answered Sep 19 '22 13:09

Ray