0

私はここで出力バッファリングを試していますが、改行や上書きで行き詰っています。

基本的に、このスニペットを CLI で実行すると:

<?php

$times = 5000;

for ($i = 1; $i <= $times; $i++)
{
    echo chr(13) . sprintf('Running step %d/%d...', $i, $times);
}

行 1 にとどまり、内容を実際のステップ情報で上書きします。

同様に、最初のステップでは、コンソール出力は次のようになります。

> php micro.php
Running step 1/5000...

ステップ 3333:

> php micro.php
Running step 3333/5000...

完了後:

> php micro.php
Running step 5000/5000...
>

ご覧のとおり、合計で、プログラムは出力のために 1 行しか消費しません。

ここで、ブラウザ用のスクリプトを微調整して、ブラウザからリクエストすると、次のようになります。

<?php

header('Content-Type: text/plain; charset=iso-8859-1');

$times = 50000;

for ($i = 1; $i <= $times; $i++)
{
    echo chr(13) . sprintf('Running step %d/%d...', $i, $times);
    flush();
    ob_flush();
}

スクリプトの処理中に出力を取得しますが、上書きされません。

同様に、最初のステップでは、コンソール出力は次のようになります。

localhost/micro.php:

Running step 1/5000...

ステップ 3333:

localhost/micro.php:

Running step 1/5000...
Running step 2/5000...
Running step 3/5000...
Running step 4/5000...
...
Running step 3333/5000...

完了後:

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...

合計で 5001 行を消費します。

行の上書きを強制するためにブラウザー出力で改行するにはどうすればよいですか?

4

2 に答える 2

0

何らかの回避策があります。反復/操作のたびに、html要素内のテキストを上書きするjavascriptをフラッシュできます。

私のテスト アプリでプログレスバーの例を見ることができます: http://darium.linuxpl.eu/tag/ - プログレスバーを表示するには、csv ファイルをアップロードして「generuj」をクリックする必要があります。

于 2015-10-15T10:49:28.757 に答える