cnastasi / async_http_client
此简单客户端允许以非阻塞方式并行执行多个请求。
v0.4.1
2016-12-28 10:44 UTC
Requires
- php: >=5.6
- react/dns: ^0.4.3
- react/promise: ^2.5
- react/react: ^0.4
Requires (Dev)
- mockery/mockery: dev-master
- phpmetrics/phpmetrics: ^1.10
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-09-18 03:32:37 UTC
README
异步Http客户端
此简单客户端允许以非阻塞方式并行执行多个请求。
先决条件
- composer
- php >=5.6
安装
composer require cnastasi\async_http_client
用法
use AsyncHttpClient\Core\AsyncHttpClient; use AsyncHttpClient\Core\AsyncHttpClientDefault; use AsyncHttpClient\Helper\TimeDefault; use AsyncHttpClient\Logger\AsyncHttpLoggerDefault; use AsyncHttpClient\Service\AsyncHttpGenericService; $loop = \React\EventLoop\Factory::create(); $dnsResolverFactory = new \React\Dns\Resolver\Factory(); $dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop); $factory = new \React\HttpClient\Factory(); $client = $factory->create($loop, $dnsResolver); $logger = new AsyncHttpLoggerDefault(new TimeDefault()); $asyncClient = new AsyncHttpClientDefault($client, $loop, $logger); $service = new AsyncHttpGenericService('GET', 'http://www.google.it', null, function ($data, $request) { // Do something }); $anotherService = new AsyncHttpGenericService('POST', 'http://www.another.service.com', http_build_query(['postfield1' => 'value']) , function ($data, $request) { // Do something more }); $asyncClient->addService($service); $asyncClient->addService($anotherService); $asyncClient->send(); // code execution will block here and the HTTP calls will be dispatched in parallel // the code execution will continue only after all http calls are dispatched and returned (callback called) // do other stuff here
贡献
- 分叉它!
- 创建你的功能分支:
git checkout -b my-new-feature
- 提交你的更改:
git commit -am '添加一些功能'
- 推送到分支:
git push origin my-new-feature
- 提交拉取请求 :D
历史
这是我在上一个圣诞节幸存下来的方法 :P