Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.



99.6k
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 registershutdownfunction just thought that may be there is something I am not aware of...

Many thanks! Appreciate it!