【问题标题】:Cygwin PHP Windows 10 Out of memoryCygwin PHP Windows 10 内存不足
【发布时间】:2020-11-05 07:14:01
【问题描述】:

4.5 GB 可用系统内存。阵列仅占用约 4 MB。 phpinfo() 报告唯一的/etc/php.ini(没有网络服务器,没有托管环境,只有我的家用电脑)。 /etc/php.inimemory_limit=-1ini_get('memory_limit') 按预期报告-1。最简单的动态数组分配,但 php 执行 exit(255) 并报告“内存不足”。

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);

正在运行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 ...]

在 x64 Windows 7 系统上运行良好(只有 800MB 可用内存),具有相同的 memory_limit 和相同的 php版本。

$ 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

只有 cygwin

如果我卸载 cygwin 版本的 php 并使用预编译的非 cygwin 版本的 php,一切都可以在 Windows 10 上运行(找不到 cygwin 文件名(例如“/usr”)除外)。

【问题讨论】:

    标签: php cygwin out-of-memory


    【解决方案1】:

    再次尝试,现在可以了。

    $ uname -a
    CYGWIN_NT-10.0 XYZ 3.1.7(0.340/5/3) 2020-08-22 17:48 x86_64 Cygwin
    
    $ php -v
    PHP 7.3.7 (cli) (built: Jul 21 2020 18:15:38) ( 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 121363 Jul 21 17:27 /usr/bin/php
    
    $ peflags --cygwin-heap /usr/bin/php
    /usr/bin/php: initial Cygwin heap size: 0 (0x0) MB
    
    

    将在 ~9 个月后删除问题

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 2018-07-21
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多