Is There Such A Thing As Afterprocessoutput() ... ?

Dear Sirs,

Here is what I would like to do in chronological order:

[list=1]

[*]Let my Action handle the request,

[*]Respond by render()

[*]Do user-specific maintenance and cleanup.

[/list]

The rub is, of course, is 3. Here is my train of thought:

After the server has sent the response, we have some ‘free time’ on the server. By ‘free time’, I mean that the server can do computations that do not affect the user-experience. After all, the user already has his response.

I would like to use this time to do some DB-logging & DB-cleanup.

  • Is there anything in Yii that can be used for this purpose?

  • There is no afterProcessOutput() in Yii 1.1.12+ … or is there?

  • When I google, I do see references to CController::afterProcessOutput(). Was this perhaps included in previous versions of Yii?

Any help is greatly appreciated…

Maybe you can use an event onEndRequest?

Perhaps. But how?

Yii Events are too difficult for me…

Does this help?

For example, I have tried the following

In config/main.php, I have added:


'onEndRequest'=>array('IfaEvents', 'ifaEndRequest'),

Then under the components directory, I have created the following file:


class IfaEvents extends CComponent

{

    

    public function ifaEndRequest($event) { 

        // code to update the Database

    }


} 

So this works, but it works too well. The DataBase is updated eight times. The event is fired eight times for each request…

But why?

Hi Keith,

Funny you came up with precisely that link.

I have looked at a bunch of tutorials and explanations, which only served to confuse me further. Except that one post on StackOverflow, which made sense…

However, as I detailed above, when copy-pasting Jonathan’s code (on SO), it fires the event no less than eight times…

That shouldn’t be happening. Can you turn on web page logging to see when the event is being raised?

Never mind. I have got it. I have EventSource running, so there is a steady stream of requests and for each End of Request, the database is now updated…

Thanks for your help!

Not sure if this is the cause of the problem, but one thing is wrong here. I wonder that it works at all…




array('IfaEvents', 'ifaEndRequest')



This defines a callback to the static method ‘ifaEndRequest’ of the class ‘IfaEvents’.

So try to define the method as being static. There are other ways to go, but this one is probably the most simple one.

Thanks, I will take a look at that.