我有一個需要將文本寫入文件的控制檯PHP應用程序。如果此大小的文本高於130999個字節,則數據將不會被寫入:exec'echo'失敗,如何查看原因?
$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
您是否記得在更改php.ini後重新啓動Web服務? –
這裏有十幾種用PHP編寫文件的原生方法。這是一個概念證明嗎? –
@Matthew:是的,我確實重啓了Apache! – dotancohen