cnastasi/async_http_client
Composer 安装命令:
composer require cnastasi/async_http_client
包简介
This simple client permits to execute multiple request in parallel, in a non blocking way.
README 文档
README
Async Http Client
This simple client permits to execute multiple request in parallel, in a non blocking way.
Prerequisites
- composer
- php >=5.6
Installation
composer require cnastasi\async_http_client
Usage
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
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request :D
History
That's the way how I survived the last Christmas :P
Credits
Thanks to Fabio Lombardo
License
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-28