In Yii2, rendering is done at the return of the controller action, so any usual echo will not be sent to the browser. But we need to give some feed back about progres in long running scripts. Here is a way to do it.
Put there two methods in a place, like CommonController class
public static function beginLongrun($time_limit){
header('X-Accel-Buffering: no');
Yii::$app->response->send();
ob_implicit_flush();
ob_end_flush();
set_time_limit($time_limit);
}
public static function echo($s){
echo $s;
ob_flush();
flush();
}
In the container action
1. First call beginLongrun
CommonController::beginLongrun(139*60);
2. then in any progress update part call echo multiple times as needed, like
CommonController::echo(intval(100 * $count / $totalCount) . '% ');
3. at then end can call rendering view like this
CommonController::echo($this->render('view-result', $data));