php - Amphp 并行是如何工作的?
问题描述
我正在阅读有关 amphp 的内容,但我对并行有疑问
示例代码:
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Amp\Artax\DefaultClient;
$promises = [];
$urls = [
"http://google.com.br",
"http://facebook.com.br",
"http://xat.com/",
"http://kobra.ninja/",
"http://wikipedia.com",
"http://manualdomundo.com.br",
"http://globo.com",
"http://gmail.com"
];
foreach ($urls as $url) {
$promises[$url] = Amp\call(function () use ($client, $url) {
// "yield" inside a coroutine awaits the resolution of the promise
// returned from Client::request(). The generator is then continued.
$response = yield $client->request($url);
// Same for the body here. Yielding an Amp\ByteStream\Message
// buffers the entire message.
$body = yield $response->getBody();
echo $url;
return $url;
});
}
$responses = Amp\Promise\wait(Amp\Promise\all($promises));
这段代码是全部运行 curl,还是等待 1 执行另一个?
解决方案
推荐阅读
- reactjs - 无法使用过滤器获取 React 表中特定列的唯一列表
- python - Django 2.2 - 使用 data-url html 属性上传图片时遇到问题
- node.js - Graphql type-graphql如何传递一个对象数组突变
- javascript - 获取键值对的嵌套对象计数
- ns-3 - 未找到 ns3 waf 配置标头
- express - 即使允许,授权标头也不会传递
- ubuntu - 将 setcap 设置为 no-root 捕获的 Wireshark dumpcap 无法在 Ubuntu 18.10 中启动
- docker - 具有确定性端口绑定的 Docker 规模
- vb.net - 当我单击一个按钮时,在运行时将新语法附加到语音识别
- django - AttributeError:“经理”对象没有属性“all_with_related_persons_and_score”