Cygwin PHP Windows 10内存不足 [英] Cygwin PHP Windows 10 Out of memory

查看:49
本文介绍了Cygwin PHP Windows 10内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

4.5 GB的可用系统内存.阵列仅占用约4 MB. phpinfo()报告一个也是唯一的/etc/php.ini (没有Web服务器,没有托管环境,只有我的家用计算机)./etc/php.ini 具有 memory_limit = -1 . ini_get('memory_limit')按预期报告 -1 .最简单的动态数组分配方法,但是php会执行 exit(255)并报告内存不足".

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".

<?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

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版本.

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

仅Cygwin

如果我卸载cygwin版本的php并使用预编译的非cygwin版本的php,则所有内容都可以在Windows 10上运行(找不到cygwin文件名(例如,"/usr")).

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

推荐答案

再次尝试,现在可以使用了.

Tried again and now it works.

$ 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个月内删除问题

will delete question in ~9 months

这篇关于Cygwin PHP Windows 10内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆