How to increase memory limit for PHP over 2GB?

跟風遠走 提交于 2019-12-17 05:01:19

问题


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.


回答1:


Have you tried using the value in MB ?

php_value memory_limit 2048M

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




回答2:


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




回答3:


For unlimited memory limit set -1 in memory_limit variable:

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



回答4:


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.




回答5:


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




回答6:


Input the following to your Apache configuration:

php_value memory_limit 2048M



回答7:


You can also try this:

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


来源:https://stackoverflow.com/questions/11885191/how-to-increase-memory-limit-for-php-over-2gb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!