首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >10内存不足

10内存不足
EN

Stack Overflow用户
提问于 2020-06-30 00:42:09
回答 1查看 255关注 0票数 5

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

temp.php

代码语言:javascript
复制
<?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;

代码语言:javascript
复制
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

代码语言:javascript
复制
$ 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系统(只有800 on的可用内存)上工作得很好,具有相同的memory_limit和相同的php版本。

代码语言:javascript
复制
$ 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版本的php并使用预编译的非cygwin版本的php,那么所有东西都可以在Windows 10上工作(除了cygwin文件名(例如"/usr") )。

EN

回答 1

Stack Overflow用户

发布于 2020-11-04 23:14:01

再试一次,现在起作用了。

代码语言:javascript
复制
$ 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个月内删除问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62648665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档