Cygwin PHP Windows 10 Out of memory

喜欢而已 提交于 2020-07-18 21:03:07

问题


4.5 GB of available system memory. Array only takes up ~4 MB. phpinfo() reports the one and only /etc/php.ini (no web servers, no hosted environment, just my home computer). /etc/php.ini has memory_limit=-1. ini_get('memory_limit') reports -1 as expected. Simplest possible dynamic array assignment, yet php does exit(255) and reports "Out of memory".

temp.php

<?php
register_shutdown_function(function()
{
    if($error = error_get_last())
    {
        var_dump($error);
        var_dump(debug_backtrace());
        passthru('free -m');
    }
});
$count=1000000;
$bigArray=array();
echo "ini_get('memory_limit')=".ini_get('memory_limit')."\n";
for($i=0;$i<$count;++$i){
  $bigArray[] = $i;
  if(rand(0,10000)==0){
    passthru('free -m');
    echo 'php memory_get_usage='.memory_get_usage(true)."\n";sleep(1);
  }
}
exit(0);

running php -f temp.php;echo "exit status=$?";free -m;

ini_get('memory_limit')=-1
              total        used        free      shared  buff/cache   available
Mem:           8075        3507        4568           0           0        4568
Swap:          5931         329        5602
php memory_get_usage=2097152
              total        used        free      shared  buff/cache   available
Mem:           8075        3507        4567           0           0        4567
Swap:          5931         329        5602
php memory_get_usage=4259840
              total        used        free      shared  buff/cache   available
Mem:           8075        3507        4567           0           0        4567
Swap:          5931         329        5602
php memory_get_usage=4259840
              total        used        free      shared  buff/cache   available
Mem:           8075        3506        4569           0           0        4569
Swap:          5931         329        5602
php memory_get_usage=4259840
[...]
              total        used        free      shared  buff/cache   available
Mem:           8075        3505        4570           0           0        4570
Swap:          5931         329        5602
php memory_get_usage=4259840
PHP Fatal error:  Out of memory (allocated 4259840) (tried to allocate 4194312 bytes) in /home/XYZ/temp.php on line 21
array(4) {
  ["type"]=>
  int(1)
  ["message"]=>
  string(67) "Out of memory (allocated 4259840) (tried to allocate 4194312 bytes)"
  ["file"]=>
  string(19) "/home/XYZ/temp.php"
  ["line"]=>
  int(21)
}
array(1) {
  [0]=>
  array(2) {
    ["function"]=>
    string(9) "{closure}"
    ["args"]=>
    array(0) {
    }
  }
}
              total        used        free      shared  buff/cache   available
Mem:           8075        3505        4570           0           0        4570
Swap:          5931         329        5602
exit status=255
              total        used        free      shared  buff/cache   available
Mem:           8075        3499        4576           0           0        4576
Swap:          5931         329        5602

Windows 10 cygwin x64

$ uname -a
CYGWIN_NT-10.0 XYZ 3.1.5(0.340/5/3) 2020-06-01 08:59 x86_64 Cygwin
$ 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
$ ulimit -v
unlimited
$ which php
/usr/bin/php
$ ls -l /usr/bin/php
-rwxr-xr-x 1 XYZ None 120339 Jul 21  2019 /usr/bin/php
$ peflags --cygwin-heap /usr/bin/php
/usr/bin/php: initial Cygwin heap size: 0 (0x0) MB
$ peflags --cygwin-heap=2048 /usr/bin/php
/usr/bin/php: initial Cygwin heap size: 2048 (0x800) MB
$ php -f temp.php
[... still a problem ...]

Works fine on a x64 Windows 7 system (with only 800MB available memory), with the same memory_limit, and same php version.

$ uname -a
CYGWIN_NT-6.1 XYZ 3.0.7(0.338/5/3) 2019-04-30 18:08 x86_64 Cygwin
$ php -v
[same as above]
    with Zend OPcache v7.3.7, Copyright (c) 1999-2018, by Zend Technologies
$ ulimit -v
unlimited
$ which php
/usr/bin/php
$ ls -l /usr/bin/php
-rwx------+ 1 XYZ None 120339 Jul 21  2019 /usr/bin/php
$ peflags --cygwin-heap /usr/bin/php
/usr/bin/php: initial Cygwin heap size: 0 (0x0) MB

Only cygwin

if I uninstall the cygwin version of php and use a pre-compiled non-cygwin version of php, everything works on Windows 10 (except cygwin file names (e.g. "/usr") are not found).

来源:https://stackoverflow.com/questions/62648665/cygwin-php-windows-10-out-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!