我想获取每个请求的传输时间。
如何将 on_stats 选项用于异步请求?
http://docs.guzzlephp.org/en/latest/request-options.html#on-stats
我的代码:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php use GuzzleHttp\\ {Pool , Client } ; use GuzzleHttp\\Psr7\\ { Request , Response } ; $httpClient = new Client ( ) ; $responses = Pool :: batch ( $httpClient , $requests , [ ‘fulfilled’ => function ( $response , $index ) { } ) ; |
- 检查这个例子,看看它是否有帮助.. guzzle.readthedocs.io/en/latest/request-options.html#on-stat??s
- @Nevermore 我不知道如何在 PSR7 请求中使用它
- @iilexial 检查这是否有帮助.. docs.guzzlephp.org/en/latest/psr7.html
- @Nevermore 我知道这个页面。此页面上没有带有 on_stats 选项的示例。
解决方案:
| 1 2 3 4 5 |
$responses = Pool :: batch ( $httpClient , $requests , [ ‘fulfilled’ => function ( $response , $index ) {
} , ‘options’ => [ ‘on_stats’ => function (TransferStats $stats ) { |
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)