出现这个错误消息,有什么建议吗?
允许内存大小为33554432字节已耗尽(已尝试分配 43148176字节)的PHP
出现这个错误消息,有什么建议吗?
允许内存大小为33554432字节已耗尽(已尝试分配 43148176字节)的PHP
当前回答
Wordpress用户添加一行:
@ini_set('memory_limit', '-1');
or
在cpanel中设置memory_limit为-1
其他回答
你可以通过执行下面的代码来增加php脚本的内存:
ini_set('memory_limit','-1'); // enabled the full memory available.
并且在脚本中取消分配不需要的变量。
我在php7.2和laravel 5.6中遇到了同样的问题。我只是增加变量memory_limit = 128M在php.ini的数量作为我的应用程序的需求。可能是256M/512M/1048M.....现在它工作得很好。
It is unfortunately easy to program in PHP in a way that consumes memory faster than you realise. Copying strings, arrays and objects instead of using references will do it, though PHP 5 is supposed to do this more automatically than in PHP 4. But dealing with your data set in entirety over several steps is also wasteful compared to processing the smallest logical unit at a time. The classic example is working with large resultsets from a database: most programmers fetch the entire resultset into an array and then loop over it one or more times with foreach(). It is much more memory efficient to use a while() loop to fetch and process one row at a time. The same thing applies to processing a file.
COMPOSER_MEMORY_LIMIT=-1 composer require mageplaza/module-core
如果你正在使用Laravel,那么可以使用以下方法:
public function getClientsListApi(Request $request){
print_r($request->all()); //for all request
print_r($request->name); //for all name
}
而不是
public function getClientsListApi(Request $request){
print_r($request); // it show error as above mention
}