I need help with a PHP memory problem. Composer and Phan both fail with Out of memory errors on my windows 10 system running cygwin php 7.3.7.
I have my memory_limit set to 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
And I have a simple program that tests the memory limits:
<?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);
}
When I run this php -f tmp/t.php 7
it predictably runs out of memory with the 'Allowed memory size exhausted' error at my 2G limit:
$ 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
But when I run it with php -f tmp/t.php 8
it dies very early with the 'Out of memory' error after allocating a measly 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
Not sure what limit it is hitting but composer update
hits a similar, but different, low limit:
$ 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