PHP code example of stk2k / grasshopper
1. Go to this page and download the library: Download stk2k/grasshopper library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stk2k / grasshopper example snippets
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;
}