如何同时执行多个Guzzle请求? [英] How to perform multiple Guzzle requests at the same time?

查看:417
本文介绍了如何同时执行多个Guzzle请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Guzzle执行单个请求,我对Guzzle的性能非常满意,但是我在Guzzle API中阅读了关于MultiCurl和Batching的一些信息。

I can perform single requests using Guzzle and I'm very pleased with Guzzle's performance so far however, I read in the Guzzle API something about MultiCurl and Batching.

有人可以向我解释如何同时做出多个请求吗?异步如果可能。我不知道这是否是他们的意思与MultiCurl。同步也不是问题。我只想在同一时间或非常接近(时间的短时间)做多个请求。

Could someone explain to me how to make multiple requests at the same time? Async if possible. I don't know if that is what they mean with MultiCurl. Sync would also be not a problem. I just want to do multiple requests at the same time or very close (short space of time).

推荐答案

在文档中:
http://guzzle3.readthedocs.org/http-client/client.html#sending-requests-in-parallel

对于一个易于使用的解决方案,返回映射到响应或错误的请求对象的哈希,请参阅 http://guzzle3.readthedocs.org/batching/batching.html#batching

For an easy to use solution that returns a hash of request objects mapping to a response or error, see http://guzzle3.readthedocs.org/batching/batching.html#batching

简短示例:

<?php

$client->send(array(
    $client->get('http://www.example.com/foo'),
    $client->get('http://www.example.com/baz'),
    $client->get('http://www.example.com/bar')
));

这篇关于如何同时执行多个Guzzle请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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