0

Normally when you call a page in Yii2, pretty much the last thing that happens is that the view is rendered to the end user's screen. I need to run code after this that might take a second or two and I don't want to have the user wait.

My first thought was to set a global event that gets called after the response is set so I added this to a method:

if (condition is met) {
    Yii::$app->on(yii\web\Response::EVENT_AFTER_SEND, function ($event) {
        // do stuff
    });
}

But this doesn't seem to ever get called. Does anyone know what I'm doing wrong or have a better idea on how to solve this problem? I just need to run code after the view is rendered. I don't really care how it happens.

3

0

Browse other questions tagged or ask your own question.