Reputation: 31481
I have a console PHP application that needs to write text to a file. If this size of the text is above 130999 bytes, then the data will not be written:
$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}");
Suspecting memory limit, I increased the PHP memory limit from 128 MB to 512 MB, with no change in the situation. What might cause this limitation?
EDIT:
Some more information:
$ 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
Upvotes: 1
Views: 332
Reputation: 146460
PHP apart, what you are basically doing is creating and running a huge command in your system's command line processor.
I suspect that all command line shells have a maximum command size. That limit is 2047 on Windows 2000 and 8191 on Windows XP [ref]. Linux will possibly have larger limits, but I don't think it'll be infinite. I'm pretty sure you've just hit your system's limit.
P.S. When PHP hits its memory limit, you get a proper error message.
Upvotes: 2