LoginSignup
0
0

More than 1 year has passed since last update.

Codeigniter4で出力バッファをフラッシュし結果を出力する方法

Last updated at Posted at 2022-09-07

概要

  • PHP 8、 Codeigniter4
  • Codeigniter4で、ob_flash() flush() を使っても処理途中での結果出力がされない
  • Codeigniter4を通さないでob_flash() flush()を実行するとちゃんと処理途中で結果表示できる

対処方法

  • ob_end_flush(); を途中出力したい処理の前でコールする。

原因

app/Config/Events.php Events::on にてob_start()がコールされている。
通常の処理を実行すると、ob_start()で出力がバッファされるため、一旦 ob_end_flush() で内部バッファの内容を出力してしまう必要がある。

出力バッファはスタッカブルなので、ob_end_flush()をせずに

ob_start();
ob_end_flush();
ob_flush();
flush();

としてしまうと、すでにバッファされているob_start() からさらに入れ子でバッファされることになるので、そのあとflushしても、最初のob_start()によりバッファされてしまう。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0