简体   繁体   English

PHP的限制为4GB而不是2GB?

[英]PHP exhausted with limit at 4GB but not 2GB?

I'm a developer in a large company that has some legacy code that requires a very large ammount of memory on export functions. 我是一家大公司的开发人员,它有一些遗留代码,需要在导出功能上有大量的内存。 To address this, ini_set('memory_limit', '4G'); 为了解决这个问题,ini_set('memory_limit','4G'); is used. 用来。

The problem is that the script crashes with memory exaustion. 问题是脚本因内存耗尽而崩溃。 If I set the limit to 2G, the script runs to the end. 如果我将限制设置为2G,脚本将运行到最后。 It doesn't even reaches 1GB peak memory usage. 它甚至达不到1GB的峰值内存使用量。

Since the code is versioned and shared with the rest of the company I can't change the limit and changing it on my local install is cumbersome. 由于代码是版本化的并与公司的其他人共享,因此我无法更改限制并在本地安装上更改它很麻烦。

My question is: what can make a script crashes with 4GB limit but not 2GB? 我的问题是:什么可以使脚本崩溃4GB限制但不是2GB?

PS: my setup is a virtualbox machine running Debian with nginx and php-fpm. PS:我的设置是使用nginx和php-fpm运行Debian的虚拟机。 The vm has 4GB RAM (although changing this doesn't seem to do any difference). vm有4GB内存(虽然改变这似乎没有任何区别)。


[ update ] [ 更新 ]

Created a new virtual machine with an 64 bits operation system and if I set the vm memory to 2GB it works. 创建了一个具有64位操作系统的新虚拟机,如果我将vm内存设置为2GB,则可以正常运行。 (If i use 4GB it doesn't). (如果我使用4GB则没有)。 Since i'm ok with 2GB, i'll close this issue. 由于我对2GB没问题,我将关闭这个问题。

It is a natural limitation: 2 or even 4 Gbs of address space are used for file mapping also which takes some memory pages. 这是一个自然的限制:2个甚至4 Gbs的地址空间也用于文件映射,这也占用了一些内存页面。

The ultimate solution would be to use the 64-bit PHP interpreter (ie, switch to 64-bit system, if possible). 最终的解决方案是使用64位PHP解释器(即,如果可能,切换到64位系统)。

Maybe you are on a 32bit system? 也许你是32位系统?

Well if your VM only has 4GB, then you probably should give it more memory. 好吧,如果你的VM只有4GB,那么你可能应该给它更多的内存。

On the 32 bit system 4GB is the limit of memory space. 在32位系统上,4GB是内存空间的限制。 I guess that there can be some memory violations when PHP tries to get 4GB memory. 我想当PHP试图获得4GB内存时可能会有一些内存违规。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM