【发布时间】:2020-08-11 23:50:04
【问题描述】:
我需要有关 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
【问题讨论】:
-
我没有答案,但我的第一个想法是搜索“如何在运行 php cli 时设置内存限制”。还有一些其他 StackOverflow 问题可能会有所帮助,例如运行包含内存限制参数的命令行或仔细检查您是否更新了正确的 php.ini。我正在阅读一些关于 CLI 的文章,它可能位于不同的位置。 stackoverflow.com/questions/43548976/…
-
你的 php 是 32 位还是 64 位? (x64 或 x86)?
-
-d memory_limit=2G标志不会改变任何东西。该系统基于 x64。 -
cygwin 也是 64 位的吗?我问这个问题:stackoverflow.com/questions/48170263/…
-
是的,我的 cygwin 安装是 64 位的。
标签: php