如何在某些情况下停止在Guzzle中发送异步请求?

时间:2018-08-14 11:05:04

标签: php guzzle6

当我发现许多异常时,我想停止在Guzzle中发送请求。有人知道怎么做吗?

这是我的代码段:

show

1 个答案:

答案 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')
            }
        }
    },