1

我有一个需要将文本写入文件的控制台 PHP 应用程序。如果此文本大小超过 130999 字节,则不会写入数据:

$line = '';
for ( $i=0 ; $i<130991 ; $i++ ) {
    $line .= 'i';
}

$size = mb_strlen($line, 'utf-8');
$line = "\n" . $size . " " . $line; // Adds another 8 bytes
$logLine = escapeshellarg($line);
echo shell_exec("echo {$logLine} >> data.log}");

怀疑内存限制,我将 PHP 内存限制从 128 MB 增加到 512 MB,情况没有任何变化。什么可能导致这种限制?

编辑:
更多信息:

$ xargs --show-limits
Your environment variables take up 3126 bytes
POSIX upper limit on argument length (this system): 2091978
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2088852
Size of command buffer we are actually using: 131072
4

1 回答 1

2

除了 PHP,您基本上所做的是在系统的命令行处理器中创建和运行一个巨大的命令。

我怀疑所有命令行 shell 都有最大命令大小。该限制在 Windows 2000 上为 2047,在 Windows XP 上为 8191 [ref]。Linux 可能会有更大的限制,但我认为它不会是无限的。我很确定你刚刚达到了系统的限制。

PS 当 PHP 达到其内存限制时,您会收到正确的错误消息。

于 2012-12-12T12:46:50.787 回答