End-Of-Lineマーカーについては、常にPHPで定義された定数を使用してください PHP_EOL
。プラットフォームに基づいて正しく設定されているので、正しいか間違っているかを心配する必要はありません。
[Enter]の問題の場合、出力バッファリングがオンになっている可能性があります。この簡単なテストをスクリプトに追加します。
function test()
{
$state = array(' added', ' skipped');
for ($i = 0; $i < 50; $i++)
{
echo 'customer id: ' . rand(1, 1000) . $state[rand(0, 1)] . PHP_EOL;
usleep(50000); // slow it a bit to see the line by line output
}
}
// without ob -------------------------------------------
$start = microtime(true);
test();
echo 'Finished in ' . round(microtime(true) - $start, 2) . PHP_EOL . str_repeat('-', 78) . PHP_EOL;
sleep(1);
// with ob ----------------------------------------------
$start = microtime(true);
ob_start(); // if called somewhere at the top in your script
// some previous code...
echo 'Line 1'.PHP_EOL.'Line 2'.PHP_EOL.uniqid().PHP_EOL;
// flush the buffer and stop ob
// this will echo whatever is in the output buffer!
//ob_end_flush();
// or, store the current buffer content in a variable and use it later
$output = ob_get_clean();
test();
echo $output;
echo 'Finished in ' . round(microtime(true) - $start, 2) . PHP_EOL . str_repeat('-', 78) . PHP_EOL;
// you could start buffering again, if needed
ob_start();
出力制御機能については、http://www.php.net/manual/en/ref.outcontrol.phpを参照してください。それらは非常に強力なツールです。
それが役に立てば幸い。乾杯!