Client
Client
HTTP Client for making requests and handling responses.
class ClientThis class provides methods for sending HTTP requests, managing cookies, headers, authentication, and handling redirects. It supports GET, POST, DELETE, TRACE, OPTIONS, and HEAD methods.
Properties
bufferSize
Buffer size for reading response data.
private int $bufferSize = 4096connectionTimeout
Connection timeout in seconds.
private int $connectionTimeout = 5headers
Request headers.
private array $headerscookies
Cookies for the request.
private array $cookieslocalCert
public string $localCertcertPassphrase
public string $certPassphraseautoRedirect
Whether to automatically follow redirects.
private bool $autoRedirect = trueredirectMethods
HTTP methods allowed for redirects.
private array $redirectMethods = array (
0 => 'GET',
1 => 'OPTIONS',
2 => 'PROPFIND',
)username
public string $usernamepassword
public string $passwordauth
public Adapter $authMethods
__construct
Constructs a new HTTP Client instance.
public __construct(?string $localCert, ?string $passphrase): voidParameters
| Parameter | Type | Description |
|---|---|---|
$localCert | string | path to local certificate file for SSL |
$passphrase | string | passphrase for the certificate file |
auth
Sets basic authentication credentials for HTTP requests.
public auth(string $username, string $password): voidStores the provided username and password for use in subsequent requests requiring authentication.
Parameters
| Parameter | Type | Description |
|---|---|---|
$username | string | the username for authentication |
$password | string | the password for authentication |
authorisation
Sets an authentication adapter for advanced authentication mechanisms.
public authorisation(Adapter $auth): voidStores the provided authentication adapter instance for use in requests requiring custom authentication.
Parameters
| Parameter | Type | Description |
|---|---|---|
$auth | Adapter | the authentication adapter instance |
setHeader
Sets a custom header for HTTP requests.
public setHeader(string $header, string $value): voidAdds or updates the specified header and value for use in subsequent requests.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | the header name |
$value | string | the header value |
options
Sends an HTTP OPTIONS request to the specified URL.
public options(string $url): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | string | the URL to send the OPTIONS request to |
get
Sends an HTTP GET request to the specified URL, with support for redirects and partial content.
public get(URL $url, int $redirectLimit = 10, int $offset = -1, ?int $maxlen): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | the URL to send the GET request to |
$redirectLimit | int | maximum number of redirects to follow |
$offset | int | byte offset for partial content (default: -1) |
$maxlen | int | maximum length of content to retrieve (optional) |
head
Sends an HTTP HEAD request to the specified URL, with support for redirects.
public head(URL $url, int $redirectLimit = 10): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | the URL to send the HEAD request to |
$redirectLimit | int | maximum number of redirects to follow |
post
Sends an HTTP POST request to the specified URL, with optional data and content type.
public post(URL $url, mixed $data, ?string $dataType, int $redirectLimit): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | the URL to send the POST request to |
$data | mixed | the data to include in the POST body (optional) |
$dataType | string | the content type of the POST data (optional, default: text/html) |
$redirectLimit | int | maximum number of redirects to follow (default: 0) |
delete
Sends an HTTP DELETE request to the specified URL.
public delete(URL $url): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | the URL to send the DELETE request to |
trace
Sends an HTTP TRACE request to the specified URL.
public trace(URL $url): ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$url | URL | the URL to send the TRACE request to |
send
Send a request to the desination host.
public send(Request $request, int $redirectLimit = 10): ?ResponseParameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | The request to send |
$redirectLimit | int | The number of allowed redirects. To disable automated redirects on this request, set to FALSE. |
getCookies
public getCookies(string $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$ | string |
getCookie
public getCookie(string $name, null $): voidParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | |
$ | null |
hasCookie
Checks if a cookie with the specified name exists.
public hasCookie(string $name): boolParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the cookie to check |
deleteCookie
Deletes a cookie with the specified name.
public deleteCookie(string $name): voidRemoves the cookie from the internal cookie storage if it exists.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the name of the cookie to delete |
setCookie
public setCookie(string $cookie): voidParameters
| Parameter | Type | Description |
|---|---|---|
$cookie | string |
cacheCookie
Caches cookies using the provided cache adapter.
public cacheCookie(CacheAdapter $cache, bool $cacheAll): boolStores all or only valid cookies in the cache, depending on the cacheAll flag.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheAdapter | the cache adapter to use for storing cookies |
$cacheAll | bool | whether to cache all cookies or only valid ones |
uncacheCookie
Restores cookies from the provided cache adapter.
public uncacheCookie(CacheAdapter $cache): boolLoads cookies from the cache and sets them in the client. Returns true if successful, false otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cache | CacheAdapter | the cache adapter to retrieve cookies from |
deleteCookies
Deletes all cookies from the client.
public deleteCookies(): voidClears the internal cookie storage.
disableRedirect
Disables automatic HTTP redirects for requests.
public disableRedirect(): voidSets the autoRedirect flag to false, preventing the client from following redirects.
applyCookies
Applies stored cookies to the given HTTP request.
private applyCookies(Request $request): RequestFilters cookies by domain, path, expiration, and security, then sets the Cookie header on the request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | Request | the request to apply cookies to |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:25 +0000