From 88e5144c675ef6ca3c9a2edd936396ace3d0e216 Mon Sep 17 00:00:00 2001 From: smetdenis Date: Mon, 1 Aug 2016 02:17:52 +0700 Subject: [PATCH] add multiRequest docs --- README.md | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7117b4f..3acecd7 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,21 @@ # JBZoo Http Client [![Build Status](https://travis-ci.org/JBZoo/Http-Client.svg?branch=master)](https://travis-ci.org/JBZoo/Http-Client) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master) -#### Useful wrapper for Guzzle and rmccue/requests +## Useful wrapper for Guzzle and rmccue/requests [![License](https://poser.pugx.org/JBZoo/Http-Client/license)](https://packagist.org/packages/JBZoo/Http-Client) [![Latest Stable Version](https://poser.pugx.org/JBZoo/Http-Client/v/stable)](https://packagist.org/packages/JBZoo/Http-Client) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/JBZoo/Http-Client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/JBZoo/Http-Client/?branch=master) -### Install +## Install ```sh +composer require guzzlehttp/guzzle --no-update # Recomended, but not required composer require jbzoo/http-client ``` -### Documentation +## Documentation "Talk is cheap. Show me the code!" (Linus Torvalds) + +#### Simple request ```php require_once './vendor/autoload.php'; // composer autoload.php @@ -20,7 +23,7 @@ require_once './vendor/autoload.php'; // composer autoload.php use JBZoo\HttpClient\HttpClient; // Configure client (no options required!) -$client = new HttpClient([ +$httpClient = new HttpClient([ 'auth' => array( // Simple HTTP auth 'http-user-name', 'http-password' @@ -68,6 +71,37 @@ $value = $json->find('key.nested', 'default', 'trim'); ``` + +## Asynchronous requests (multi curl, in parallel) +```php + +$httpClient = new HttpClient(); + +$results = $httpClient->multiRequest(array( + 'request_0' => array('http://mockbin.org/request'), + 'request_1' => array('http://mockbin.org/request', array( + 'args' => array('key' => 'value') + )), + 'request_2' => array('http://mockbin.org/request', array( + 'method' => 'post', + 'args' => array('key' => 'value') + 'headers' => array( // You custom headers + 'X-Custom-Header' => 42, + ), + 'timeout' => 10, + 'verify' => false, + 'exceptions' => false, + 'allow_redirects' => true, + 'max_redirects' => 10, + 'user_agent' => 'JBZoo/Http-Client v1.x-dev' + )) +)); + +$results['request_0']->getBody(); +$results['request_1']->getBody(); +$results['request_2']->getBody(); +``` + ## Unit tests and check code style ```sh make