1. Go to this page and download the library: Download cvweiss/guzzler 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/ */
cvweiss / guzzler example snippets
use cvweiss\Guzzler;
$guzzler = new Guzzler();
$params = []; // Parameters to share with the success and fail function. Not t "
$guzzler->call("https://example.org", "success", "fail", $params, $headers, $requestType);
function success(&$guzzler, &$params, $content)
{
// Do stuff with the successful return
}
function fail(&$guzzler, &$params, $exception)
{
// Do stuff with the failed return
}
$guzzler->tick();
$guzzler->finish();
$guzzler = new Guzzler($concurrentRequests, $utimeSleep);
$userAgent= "MyAppName Example";
$guzzler = new Guzzler($concurrentRequests, $utimeSleep, $userAgent);
function success(&$guzzler, &$params, $content)
{
$headers = $guzzler->getLastHeaders(); // Retrieves headers for this request
$etag = $headers['etag'][0]; // Each header is an array (thanks curl). Use [0] to get the value of the header in most cases.
}
$headers = [];
$headers['User-Agent'] = "My Application";
$headers['If-None-Match'] = '"09f8b2541e00231360e70eb9d4d6e6504a298f9c8336277c704509a8"'; // ETag example
$guzzler->call("https://example.org", "success", "fail", $params, $headers);
$guzzler->call("https://example.org", "scucess", "fail"); // IllegalArgumentException returned since you have not defined the function 'scucess'
function success(&$guzzler, &$params, $content)
{
}
$headers = [];
$headers['etag'] = $redis;
$guzzler->call("https://example.org", "success", "fail", $params, $headers);
function success(&$guzzler, &$params, $content)
{
// $content will equal "" on a successful etag return
}
use cvweiss\Guzzler;
$data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
$guzzler = new Guzzler(1, 1000000); // One concurrent request, waiting up to one second on ticks
foreach ($data as $id) {
$guzzler->call("https://example.org?page=" . $page", "success", "fail", $params, $headers, "GET"); // Preps the request
$guzzler->tick(); // Allows the above request to be started and allows previous requests to be processed and completed.
}
$guzzler->finish(); // Waits for all requests to be processed and completed.
// This function is called when the request is successful
function success(&$guzzler, &$params, $content)
{
echo $content . "\n";
}
// This function is called when the request has failed
function success(&$guzzler, &$params, $exception)
{
echo $exception->getMessage() . "\n";
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.