4.5 GB可用系统内存。数组只占用~4MB。phpinfo()报告唯一的/etc/php.ini (没有web服务器,没有托管环境,只有我的家用计算机)。/etc/php.ini有memory_limit=-1。ini_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 5602Windows 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系统(只有800 on的可用内存)上工作得很好,具有相同的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版本的php并使用预编译的非cygwin版本的php,那么所有东西都可以在Windows 10上工作(除了cygwin文件名(例如"/usr") )。
发布于 2020-11-04 23:14:01
再试一次,现在起作用了。
$ 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个月内删除问题
https://stackoverflow.com/questions/62648665
复制相似问题