1

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.

enter image description here

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
  • I don't have an answer, but my first thought was to search for "how to set memory limit when running php cli". There are a couple other StackOverflow questions that might help, such as running your command line with the memory limit argument included or to double-check that you are updating the correct php.ini. I'm reading in some articles that for CLI, it could be in a different spot. https://stackoverflow.com/questions/43548976/how-do-i-set-the-memory-limit-for-php-cli-when-using-xampp – David Tran Aug 12 '20 at 00:16
  • Is your php 32bits or 64bits? (x64 or x86) ? – Felippe Duarte Aug 12 '20 at 00:29
  • The `-d memory_limit=2G` flag doesn't change anything. The system is x64 based. – Dan Schmidt Aug 12 '20 at 00:51
  • Is cygwin also 64 bit? I ask due to this question: https://stackoverflow.com/questions/48170263/composer-runs-out-of-memory-cannot-work-around – EPB Aug 12 '20 at 00:55
  • Yes, my cygwin install is 64-bit. – Dan Schmidt Aug 12 '20 at 02:48

1 Answers1

0

It turned out that I did another Cygwin update and it updated a bunch of php modules. That fixed my problem. I had done a Cygwin update just about 10 days ago so thee must have been a bug in that small window of Cygwin php modules.

Glad to have this fixed. Sorry to all those who spent time thinking about it for me.