如何同时执行多个 Guzzle 请求? [英] How to perform multiple Guzzle requests at the same time?
问题描述
我可以使用 Guzzle 执行单个请求,并且我对 Guzzle 迄今为止的性能非常满意,但是,我在 Guzzle API 中阅读了有关 MultiCurl 和批处理的内容.
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#并行发送请求
有关返回映射到响应或错误的请求对象散列的易于使用的解决方案,请参阅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屋!