Loader
Simple loader to send request and read response from address. Uses cURL extension. Composer package.
Install
composer require greezlu/ws-loader
Basic usage
Create Loader instance with request params in the constructor. Use load method to get Response object. Get data from Response object.
Example
$loader = new \WebServer\Core\Loader('https://raw.githubusercontent.com/greezlu/ws-loader/master/composer.json');
$response = $loader->load();
$response->toString();
Loader object
Main class to send response. cURL Settings.
WebServer\Core\Loader
/* Default script pause time after successful request. */
private Loader::DEFAULT_LOAD_TIMEOUT = 500000;
public Loader::__construct(
string $address,
string $method = 'GET',
array $requestParams = [],
int $requestTimeout = self::DEFAULT_LOAD_TIMEOUT
)
/* Example */
$requestParams = [
'headers' => ['Header-Name' => 'Header Value'],
'cookie' => ['Cookie-Name' => 'Cookie Value'],
'curlSettings' => ['Setting-Name' => 'Setting Value'],
'postParams' => ['Param-Name' => 'Param Value'],
'getParams' => ['Param-Name' => 'Param Value']
];
/* Send request and return response object or null. */
public Loader::load(): ?Response
LoaderResponse object
Can be converted to string using magic method.
WebServer\Core\LoaderResponse
/* Get raw response as string data. */
public LoaderResponse::toString(): string
/* Attempt to decode response. Return result or empty array. */
public LoaderResponse::toArray(): array
/* Get response status code. */
public LoaderResponse::getResponseStatusCode(): array
/* Get list of response headers. */
public LoaderResponse::getResponseHeaders(): array