We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PostResponseEvent for Phalcon

We have an event which is called 'finish' in Micro:

$app->finish( function () use ($app) { // This is executed when the request has been served } );

but a response is still not sent. Do we have the similar one like PostResponseEvent in Symphony in Application/Micro or at least some event that will be triggered after response is sent?

Thanks in advance!

No, there is not.

@IronArt1: you mean some event that will execute after the route handler returns response and output buffer is flushed to the client?

Isn't finish() event good for you?

If I remember correctly that's exactly what you want. Take into account sync nature of PHP, that means flushing output buffers will always come at the end of request, meaning that finish() will get triggered before sending response to the client.

Yea i guess he needs something after sending response to client. Then it's obviously not possible.

@IronArt1: you mean some event that will execute after the route handler returns response and output buffer is flushed to the client?

Isn't finish() event good for you?

If I remember correctly that's exactly what you want. Take into account sync nature of PHP, that means flushing output buffers will always come at the end of request, meaning that finish() will get triggered before sending response to the client.

Yes, I need an event which could be triggered after a response is sent to a client.



145.0k
Accepted
answer
edited Feb '17

Then only way i see is just to use php shutdown function - https://secure.php.net/manual/en/function.register-shutdown-function.php This is just before output buffers are send to client. Of course it's not possible to send AFTER cuz of php nature. If you really need this then i would add here some job to queue and just handle it in some cli task if you need to do something after sending response to client, like log something.

Then only way i see is just to use php shutdown function - https://secure.php.net/manual/en/function.register-shutdown-function.php This is just before output buffers are send to client. Of course it's not possible to send AFTER cuz of php nature. If you really need this then i would add here some job to queue and just handle it in some cli task if you need to do something after sending response to client, like log something.

Yes, there are some log issues... And I have already used register_shutdown_function just thought that may be there is something I am not aware of...

Many thanks! Appreciate it!