出现这个错误消息,有什么建议吗?
允许内存大小为33554432字节已耗尽(已尝试分配 43148176字节)的PHP
出现这个错误消息,有什么建议吗?
允许内存大小为33554432字节已耗尽(已尝试分配 43148176字节)的PHP
当前回答
在Wordpress中切换到一个新主题后,我收到了同样的错误信息。PHP运行的是5.3版本,所以我切换到了7.2。这解决了问题。
其他回答
如果您的脚本需要分配这么大的内存,那么您可以通过在php文件中添加这一行来增加内存限制
ini_set('memory_limit', '44M');
其中,4400万是你预计消费的数量。
但是,大多数情况下,此错误消息意味着脚本正在做错误的事情,增加内存限制只会导致相同的错误消息,但数字不同。
因此,您必须重写代码,而不是增加内存限制,这样它就不会分配那么多内存。例如,在较小的块中处理大量数据,取消保存大值但不再需要的变量,等等。
这里有两个简单的方法来增加共享主机的限制:
如果您可以访问PHP.ini文件,请更改PHP.ini中的行 如果你的线显示为32M,试试64M: memory_limit = 64M;一个脚本可能消耗的最大内存(64MB) 如果你不能访问PHP.ini,试着把这个添加到。htaccess文件中: php_value memory_limit 64M
I was also having the same problem, looked for phpinfo.ini, php.ini or .htaccess files to no avail. Finally I have looked at some php files, opened them and checked the codes inside for memory. Finally this solution was what I come out with and it worked for me. I was using wordpress, so this solution might only work for wordpress memory size limit problem. My solution, open default-constants.php file in /public_html/wp-includes folder. Open that file with code editor, and find memory settings under wp_initial_constants scope, or just Ctrl+F it to find the word "memory". There you will come over WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT. Just increase it, it was 64 MB in my case, I increased it to 128 MB and then to 200 MB.
// Define memory limits.
if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MEMORY_LIMIT', $current_limit );
} elseif ( is_multisite() ) {
define( 'WP_MEMORY_LIMIT', '200M' );
} else {
define( 'WP_MEMORY_LIMIT', '128M' );
}
}
if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
} elseif ( -1 === $current_limit_int || $current_limit_int > 268435456 /* = 256M */ ) {
define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
} else {
define( 'WP_MAX_MEMORY_LIMIT', '256M' );
}
}
顺便说一句,请不要做下面的代码,因为这是不好的做法:
ini_set('memory_limit', '-1');
我有同样的问题,在命令行运行php。最近,我更改了php.ini文件,在更改php.ini时犯了一个错误
这是针对php7.0的
到php.ini的路径:/etc/php/7.0/cli/php.ini
我设置了memory_limit = 256(这意味着256字节),而不是memory_limit = 256M(这意味着256兆字节)。
; 脚本可能消耗的最大内存(128MB) ; http://php.net/memory-limit memory_limit = 128M
一旦我纠正了它,我的过程开始正常运行。
你的脚本占用了太多内存。在PHP中,如果有一个超出控制的循环,并且每次循环都要创建对象或向数组中添加内容,则经常会发生这种情况。
检查有无无限循环。
如果这不是问题,尝试通过将对象设置为null来销毁它们来帮助PHP。如。$OldVar = null;
还要检查实际发生错误的代码。你认为这一行会分配大量的内存吗?如果没有,试着找出哪里出了问题。