Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5: Send a response first, then process request in controller

I'm working with the Classic Paypal API and I'm stuck on a problem of responding before I process the request data.

public function store() {
    // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
    response("", 200);
    // Build the required acknowledgement message out of the notification just received
    // Once it hits this point, nothing is sent to the client.
}

I know that in order for the client to receive the HTTP 200 response, I will need to add the return keyword in front of it. However, if I return the response immediately, then the processing of the request will not occur. I looked into before and after middlewares, but unfortunately they are not asynchronous. Is there any way of accomplishing a send then process in Laravel 5?

like image 759
jon5477 Avatar asked Jun 10 '15 18:06

jon5477


1 Answers

I found a hack solution to this problem:

try {
    return response("", 200);
} finally {
    // Controller logic here
}
like image 138
jon5477 Avatar answered Oct 12 '22 06:10

jon5477