How to increase memory limit for PHP over 2GB?

PhpMemory Limit

Php Problem Overview


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.

Php Solutions


Solution 1 - Php

Have you tried using the value in MB ?

php_value memory_limit 2048M

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

Solution 2 - Php

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).

Solution 3 - Php

For unlimited memory limit set -1 in memory_limit variable:

ini_set('memory_limit', '-1');

Solution 4 - Php

You should have 64-bit OS on hardware that supports 64-bit OS, 64-bit Apache version and the same for PHP. But this does not guarantee that functions that are work with PDF can use such big sizes of memory. You'd better not load the whole file into memory, split it into chunks or use file functions to seek on it without loading to RAM.

Solution 5 - Php

For others who are experiencing with the same problem, here is the description of the bug in php + patch https://bugs.php.net/bug.php?id=44522

Solution 6 - Php

You can also try this:

ini_set("max_execution_time", "-1");
ini_set("memory_limit", "-1");
ignore_user_abort(true);
set_time_limit(0);

Solution 7 - Php

Input the following to your Apache configuration:

php_value memory_limit 2048M

Solution 8 - Php

I had the same problem with commandline php even when ini_set("memory_limit", "-1"); was set, so the limit is in php not from apache.

You should check if you are using the 64bit version of php.

Look at this question about Checking if code is running on 64-bit PHP to find out what php you are using.

I think your php is compiled in 32 bit.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmikikgView Question on Stackoverflow
Solution 1 - PhpClaudiu ClawView Answer on Stackoverflow
Solution 2 - PhpRayView Answer on Stackoverflow
Solution 3 - PhpIndrajeet SinghView Answer on Stackoverflow
Solution 4 - PhpTimurView Answer on Stackoverflow
Solution 5 - PhpWiggler JtagView Answer on Stackoverflow
Solution 6 - Phpkishan RadadiyaView Answer on Stackoverflow
Solution 7 - PhpFlorentView Answer on Stackoverflow
Solution 8 - PhpRadon8472View Answer on Stackoverflow