1. Go to this page and download the library: Download pretorien/request 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/ */
use Pretorien\RequestBundle\Service\RequestService;
use Pretorien\RequestBundle\Http\Request\Request;
/* ... */
public function myFunction(RequestService $requestService)
{
$url = "http://www.example.com";
$options = [];
$response = $requestService->publicRequest($url, Request::METHOD_GET, $options);
$response = $requestService->privateRequest($url, Request::METHOD_GET, $options);
/* ... */
}
use Pretorien\RequestBundle\Service\RequestService;
/* ... */
public function myFunction(RequestService $requestService)
{
$url = "http://www.example.com";
$response = $requestService->privateRequest($url, [$method, $options]);
// getting the response headers waits until they arrive
$contentType = $response->getHeaders()['content-type'][0];
// trying to get the response contents will block the execution until
// the full response contents are received
$contents = $response->getContent();
}
use Pretorien\RequestBundle\Service\RequestService;
use Pretorien\RequestBundle\Http\Response\PoolResponse;
use Pretorien\RequestBundle\Http\Request\PrivateRequest;
use Pretorien\RequestBundle\Http\Request\PublicRequest;
/* ... */
public function myFunction(RequestService $requestService)
{
$url = "http://www.example.com";
$pool = $requestService->createPoolRequest();
$privateRequest = new PrivateRequest($url);
$publicRequest = new PublicRequest($url);
$pool->addRequest($privateRequest);
$pool->addRequest($publicRequest);
$poolResponse = $requestService->sendPoolRequest($pool);
}
use Pretorien\RequestBundle\Service\RequestService;
use Pretorien\RequestBundle\Http\Response\PoolResponse;
use Pretorien\RequestBundle\Http\Request\PrivateRequest;
use Pretorien\RequestBundle\Http\Request\PublicRequest;
/* ... */
public function myFunction(RequestService $requestService)
{
$url = "http://www.example.com";
$pool = $requestService->createPoolRequest();
$privateRequest = new PrivateRequest($url);
$publicRequest = new PublicRequest($url);
$pool->addRequest($privateRequest);
$pool->addRequest($publicRequest);
$poolResponse = $requestService->sendPoolRequest($pool);
$responses = $poolResponse->getContents();
foreach ($responses[PoolResponse::RESPONSES_SUCCESSFUL] as $response) {
$content = $response['content'];
$request = $response['request'];
$httpClientResponse = $response['response'];
}
foreach ($responses[PoolResponse::RESPONSES_FAILED] as $response) {
$exception = $response['exception'];
$request = $response['request'];
$httpClientResponse = $response['response'];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.