stk2k / grasshopper
Thin wrapper class library of cURL
0.8.1
2018-01-24 17:30 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
- dev-master
- 0.8.1
- 0.8.0
- 0.7.11
- 0.7.10
- 0.7.9
- 0.7.8
- 0.7.7
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.12
- 0.3.11
- 0.3.10
- 0.3.9
- 0.3.8
- 0.3.7
- 0.3.6
- 0.3.5
- 0.3.4
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3.0
- 0.2.9
- 0.2.8
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.1.0
This package is auto-updated.
Last update: 2024-12-12 05:49:54 UTC
README
Description
Grasshopper is a yet another cURL PHP library wchich makes you easy to send HTTP request. This library can process multiple requests at once.
Feature
- supports process multiple requests in one call
- easy to use: simple interface
- variety of error handling: both supported procedural or callback
Demo
use Grasshopper\Grasshopper; use \Grasshopper\event\SuccessEvent; use \Grasshopper\event\ErrorEvent; $hopper = new Grasshopper(); $url = 'http://example.com'; $hopper->addRequest($url); $result = $hopper->waitForAll(); $res = $result[$url]; if ( $res instanceof SuccessEvent ){ // success $status = $res->getResponse()->getStatusCode(); $body = $res->getResponse()->getBody(); echo "success: status=$status" . PHP_EOL; echo $body . PHP_EOL; } elseif ( $res instanceof ErrorEvent ){ // error echo "error: " . $res->getError()->getMessage() . PHP_EOL; }
Usage
- create grashopper object.
- add HttpGet/HttpPostRequest to grasshopper object.
- execute Grasshopper#waitforAll() method.
- get response from returned array.the key is requested URL.
- check response object whether SuccessEvent or ErrorEvent.SuccessEvent means request was succeeded, ErrorEvent means failure.
- you can get response object from SuccessEvent. it provides status code and response body.
- you can get error information from ErrorEvent. it provides error code and message.
Requirement
PHP 5.5 or later
Installing Grasshopper
The recommended way to install Grasshopper is through Composer.
composer require stk2k/grasshopper
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.