问题描述
我尝试在php.ini中设置限制,但我总是遇到相同的错误:
I have tried setting the limit in php.ini but I always get the same error:
已允许用尽262144字节的内存(尝试分配341351字节)在第0行上的未知中
Allowed memory size of 262144 bytes exhausted (tried to allocate 341351 bytes) in Unknown on line 0
我可以通过调用 php -d memory_limit = 2048M script.php
I can work around this by calling php -d memory_limit=2048M script.php
但无法弄清楚如何使用作曲家。
But can't figure out what to do with composer.
推荐答案
在最顶端将其添加到PHP脚本中的PHP
ini_set( memory_limit, 2048M); 的代码中。请确保根据您的需要增加 memory_limit 。
Add this at the very top your code of PHPini_set("memory_limit", "2048M"); in your PHP script. Make sure to increase memory_limit according to your need.
如果继续收到这种内存耗尽。您可以使用 ini_set( memory_limit, -1); 。这会将您的内存限制设置为无限制。
If you keep on getting this kind of error message of exhausted memory. you can use ini_set("memory_limit", "-1");. This will set your memory limit to no limit.
注意:另外,请确保您是否正在使用PHP脚本在生产环境中执行某些操作,而该脚本的工作仍在继续在静态变量(示例: 收集多个CSV数据)或某些数组中向其中的脚本添加数据,则可能导致失败完全耗尽内存的情况下该VM或PHP进程的大小。
Note: Also please make sure if you are doing something on your production environment in your PHP script, whose job is to keep on adding data to there script, either in your static variables(Example: gathering multiple CSV's data) or some arrays, then it can lead to either failure of that VM or PHP process in case of complete memory exhaust.
这篇关于使用xampp时如何为PHP CLI设置memory_limit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!