php - Flushing output to browser, carriage return and overwrite? -
i'm experimenting here output buffering , stuck on carriage returns, overwrites.
basically, if run snippet in cli:
<?php $times = 5000; ($i = 1; $i <= $times; $i++) { echo chr(13) . sprintf('running step %d/%d...', $i, $times); }
it stay on line 1 , overwrite contents actual step information.
like, on first step console output be:
> php micro.php
running step 1/5000...
on step 3333:
> php micro.php
running step 3333/5000...
after completition:
> php micro.php
running step 5000/5000...
>
as can see, in total, program have consumed 1 line it's output.
now, if tweak script browser , request browser:
<?php header('content-type: text/plain; charset=iso-8859-1'); $times = 50000; ($i = 1; $i <= $times; $i++) { echo chr(13) . sprintf('running step %d/%d...', $i, $times); flush(); ob_flush(); }
i output while script being processed, but, not overwritten.
like, on first step console output be:
localhost/micro.php:
running step 1/5000...
on step 3333:
localhost/micro.php:
running step 1/5000...
running step 2/5000...
running step 3/5000...
running step 4/5000...
...
running step 3333/5000...
after completition:
localhost/micro.php:
running step 1/5000...
running step 2/5000...
running step 3/5000...
running step 4/5000...
...
running step 3333/5000...
...
running step 5000/5000...
in total consuming 5001 lines.
how carriage return in browser output force line overwrite?
as far know, can't.
the way see implement progress bar in browser involves javascript, , ajax requests poll server on progress status.
Comments
Post a Comment