php - Terminal output is slower than file write? -


i wrote small script generate email addresses based on pattern:

<?php $host = '@gmail.com'; $prefix = 'email'; $total = 200000;  for($i = 0; $i <$total; $i++) {     echo $prefix . $i . $host . php_eol; } 

now, if run script $php generate.php takes around 15 seconds complete output echo. however, redirecting output ($php generate.php > file) completes within second.

is php's buffering mechanism's or part of linux behavior?

this linux causing slowdown. same happen if printed output in windows console. each flush of output obliging program halt, operating system update window, , program given control continue again. if these flushes numerous , often, may indeed slow down things quite bit.

writing file still requires operating system step in, there no overhead beyond you'd see program reads , writes files. said, writing console handy tool debugging program , should use it. sure when runs on production machine, writes file log instead.


Comments