当我发现许多异常时,我想停止在Guzzle中发送请求。有人知道怎么做吗?
这是我的代码段:
show
答案 0 :(得分:0)
rejected
回调有第四个参数,它代表整个EachPromise
。您可以根据情况拒绝它,它将停止执行流程。
'rejected' => function ($reason, $index, $idx, $aggregate) {
// This is delivered each failed request
if ($reason instanceof GuzzleException) {
if ($this->reject++ > 30) {
$aggregate->reject('Attempts limit exceeded')
}
}
},