Laravel 5:首先发送响应,然后在控制器中处理请求 [英] Laravel 5: Send a response first, then process request in controller

查看:186
本文介绍了Laravel 5:首先发送响应,然后在控制器中处理请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Classic Paypal API,在处理请求数据之前遇到了响应问题.

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.
}

我知道,为了让客户端接收HTTP 200响应,我需要在其前面添加return关键字.但是,如果我立即返回响应,那么将不会进行请求的处理.我研究了中间件之前和之后,但不幸的是它们不是异步的. Laravel 5中有什么方法可以完成发送然后处理过程?

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?

推荐答案

我找到了解决此问题的方法:

I found a hack solution to this problem:

try {
    return response("", 200);
} finally {
    // Controller logic here
}

这篇关于Laravel 5:首先发送响应,然后在控制器中处理请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆