php guzzle并发,在Guzzle中访问被拒绝的并发请求的响应

我正在使用Guzzle并发请求工具:

http://docs.guzzlephp.org/en/latest/quickstart.html#concurrent-requests

我的代码类似于示例代码:

use GuzzleHttp\Pool;

use GuzzleHttp\Client;

use GuzzleHttp\Psr7\Request;

$client = new Client();

$requests = function ($total) {

$uri = 'http://127.0.0.1:8126/guzzle-server/perf';

for ($i = 0; $i < $total; $i++) {

yield new Request('GET', $uri);

}

};

$pool = new Pool($client, $requests(100), [

'concurrency' => 5,

'fulfilled' => function ($response, $index) {

// this is delivered each successful response

},

'rejected' => function ($reason, $index) {

// this is delivered each failed request

},

]);

// Initiate the transfers and create a promise

$promise = $pool->promise();

// Force the pool of requests to complete.

$promise->wait();

问题是我的一些请求返回了500个HTTP响应的响应,但仍然发送了一些内容(例如,错误发生的原因).不幸的是,Guzzle将具有500个状态代码的http响应分类为“被拒绝”,并且我似乎无法获得原始响应,因为该参数在被拒绝的函数中不存在.

然而,我可以访问$reason.在我的例子中,它包含一个像这样的JSON:

{

xdebug: "..."

}

xdebug属性包含HTML作为字符串,如下所示:

GuzzleHttp\Exception\ServerException: Server error: `GET

07001 resulted in a `500 Internal Server Error`

response: {“failure_reason”:”Useful message”} in […stacktrace …]

虽然这包含原始响应,但我不能轻易地将其提取为隐藏在HTML中,使其非常无用.我也不知道这是如何设置的.

因此我的问题是,如何访问被拒绝的并发请求的响应?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值