php - PHP内存不足与允许的内存大小耗尽
问题描述
我需要有关 PHP 内存问题的帮助。Composer 和 Phan 在运行 cygwin php 7.3.7 的 Windows 10 系统上均因内存不足错误而失败。
我的 memory_limit 设置为 2G
$ php -v
PHP 7.3.7 (cli) (built: Jul 21 2019 18:10:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.7, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.9.4, Copyright (c) 2002-2020, by Derick Rethans
$ php -i | grep memory
memory_limit => 2G => 2G
Collecting memory statistics => No
我有一个简单的程序来测试内存限制:
<?php
echo "Memory test...\n";
$argv = $_SERVER['argv'];
$step = $argv[1] * 1024 * 1024;
$a = [];
while (1)
{
echo " ". memory_get_usage(true). " bytes used. Allocating another ~$step bytes\n";
$a[] = str_repeat('a', $step);
}
当我运行php -f tmp/t.php 7
它时,它可以预见地会在我的 2G 限制处出现“允许的内存大小已用完”错误的内存不足:
$ php -f tmp/t.php 7
Memory test...
2097152 bytes used. Allocating another ~7340032 bytes
9502720 bytes used. Allocating another ~7340032 bytes
16908288 bytes used. Allocating another ~7340032 bytes
...
2105278464 bytes used. Allocating another ~7340032 bytes
2112684032 bytes used. Allocating another ~7340032 bytes
2120089600 bytes used. Allocating another ~7340032 bytes
2127495168 bytes used. Allocating another ~7340032 bytes
2134900736 bytes used. Allocating another ~7340032 bytes
2142306304 bytes used. Allocating another ~7340032 bytes
Fatal error: Allowed memory size of 2147483648 bytes exhausted (tried to allocate 7340064 bytes) in /cygdrive/c/Users/dschmidt/tmp/t.php on line 13
Call Stack:
0.0005 403664 1. {main}() /cygdrive/c/Users/dschmidt/tmp/t.php:0
0.8291 2140640320 2. str_repeat() /cygdrive/c/Users/dschmidt/tmp/t.php:13
但是当我用它运行它时,php -f tmp/t.php 8
在分配了区区的 10M 后,它很早就因“内存不足”错误而死:
$ php -f tmp/t.php 8
Memory test...
2097152 bytes used. Allocating another ~8388608 bytes
10551296 bytes used. Allocating another ~8388608 bytes
Fatal error: Out of memory (allocated 10551296) (tried to allocate 8388640 bytes) in /cygdrive/c/Users/dschmidt/tmp/t.php on line 13
Call Stack:
0.0005 403664 1. {main}() /cygdrive/c/Users/dschmidt/tmp/t.php:0
0.0055 8858240 2. str_repeat() /cygdrive/c/Users/dschmidt/tmp/t.php:13
不确定它达到了什么限制,但composer update
达到了类似但不同的下限:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Fatal error: Out of memory (allocated 57671680) (tried to allocate 2110325 bytes) in phar:///cygdrive/c/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Util/RemoteFilesystem.php on line 462
解决方案
原来我做了另一个 Cygwin 更新,它更新了一堆 php 模块。这解决了我的问题。大约 10 天前我完成了 Cygwin 更新,所以你一定是 Cygwin php 模块的那个小窗口中的一个错误。
很高兴能解决这个问题。对不起所有花时间为我考虑的人。
推荐阅读
- vb.net - 选择 TreeViewAdv 中最后添加的节点
- c# - 在控制之外处理 DragDrop - DragEnd 事件?
- c++ - 计算字符串中字符出现次数时出错
- excel - 通过匹配两个不同列中的值对行进行排序
- javascript - 在 json.stringify 中组合替换器和字段
- javascript - VueJS 没有被渲染
- java - 有没有办法在 TextView 中自动选择文本?
- android - 如何使用 Kodein 为工厂类实例化许多参数
- perl - 在 SSH 终端中执行的命令显示额外的行内容
- java - 如何在此应用程序中保持图像视图的纵横比?【Android、ImageView、长宽比、ScrollView】