PHP CLI 脚本还可以如何确定其内存限制?
我需要运行 PHP CLI 脚本并为其提供大量内存(它是一个自动文档生成器,需要覆盖大型代码库)。我有一台功能强大的机器,并在 php.ini
和脚本文件中的内联 ini_set('memory_limit','5120M')
声明中为 php 分配了 5GB 。
如果我将这些行添加到脚本顶部:
phpinfo();
exit();
...它声称它的内存限制为 5120M,正如我指定的那样。
但脚本仍然出错,显示
Fatal error: Allowed memory size of 1073741824 bytes exhausted
...这是 1GB,而不是我指定的 5GB。
脚本是否还有其他地方可以确定其内存限制?它在 Fedora Linux 中运行。
(是的,最终的解决方案可能是重写脚本以提高效率,但我一开始就没有编写它,所以在我采取这种方法之前,我想向它投入资源,看看是否有效。 )
I need to run a PHP CLI script and give it a LOT of memory (it's an automatic documentation generator that needs to cover a large code base). I have a powerful machine and have allocated 5GB to php, both in php.ini
and in an inline ini_set('memory_limit','5120M')
declaration in the script file.
If I add these lines to top of the script:
phpinfo();
exit();
... it claims that it has a memory limit of 5120M, as I specified.
But the script still errors out, saying
Fatal error: Allowed memory size of 1073741824 bytes exhausted
... which is 1GB, not 5GB as I specified.
Is there any other place that the script might be looking to determine its memory limit? This is running in Fedora Linux.
(Yes, the ultimate solution may be to rewrite the script to be more efficient, but I didn't write it in the first place, so before I resort to that, I want to just throw resources at it and see if that works.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
堆限制属性是一个size_t,在32位机器上是32位。如果以字节为单位,则会将内存限制限制为 4 GB。您可以尝试在 64 位计算机上使用 64 位 PHP 运行它。
编辑:确认,heap->limit 是一个 size_t (无符号整数)并且以字节为单位。 Memory_limit 为 -1 将堆限制设置为 4GB,并且不会像文档所暗示的那样禁用它。将其设置为 5GB 会使其环绕至 1GB。
The heap limit property is a size_t, which is 32 bits on a 32-bit machine. If this is in bytes, this would limit the memory limit to 4 GB. You may try running it on a 64 bit machine, with 64-bit PHP.
Edit: confirmed, heap->limit is a size_t (unsigned int) and is in bytes. A memory_limit of -1 sets the heap->limit to 4GB, and does not disable it as the documentation implies. Setting it to 5GB makes it wrap around to 1GB.