食人鱼异步多个承诺

因此,我正在尝试将guzzle用于几个并发请求。我在网上看到了几个示例,这是我想出的,但似乎无法使其正常工作。没有错误,没有警告,什么都没有。我已经尝试在每个诺言中登录,但没有任何反应。


而且我肯定知道什么都不会发生,因为什么都没有插入数据库中。有什么想法我想念的吗?(我产生每个请求及其各自的请求,then因为在每个承诺结束时,数据库操作特定于该用户)


use GuzzleHttp\Promise\EachPromise;

use Psr\Http\Message\ResponseInterface;


$promises = (function () use($userUrls){

    $userUrls->each(function($user) {

        yield $this->client->requestAsync('GET', $user->pivot->url)

            ->then(function (ResponseInterface $response) use ($user) {

                $this->dom->load((string)$response->getBody());

                // ... some db stuff that inserts row in table for this

                // $user with stuff from this request

            });

    });

});


$all = new EachPromise($promises, [

    'concurrency' => 4,

    'fulfilled' => function () {


    },

]);


$all->promise()->wait();


慕沐林林
浏览 125回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP