Documentation

Client
in package
implements ClientInterface, ClientInterface uses ClientTrait

Tags
final

Table of Contents

Interfaces

ClientInterface
Client interface for sending HTTP requests.
ClientInterface

Properties

$config  : array<string|int, mixed>

Methods

__call()  : PromiseInterface|ResponseInterface
__construct()  : mixed
Clients accept an array of constructor parameters.
delete()  : ResponseInterface
Create and send an HTTP DELETE request.
deleteAsync()  : PromiseInterface
Create and send an asynchronous HTTP DELETE request.
get()  : ResponseInterface
Create and send an HTTP GET request.
getAsync()  : PromiseInterface
Create and send an asynchronous HTTP GET request.
getConfig()  : mixed
Get a client configuration option.
head()  : ResponseInterface
Create and send an HTTP HEAD request.
headAsync()  : PromiseInterface
Create and send an asynchronous HTTP HEAD request.
patch()  : ResponseInterface
Create and send an HTTP PATCH request.
patchAsync()  : PromiseInterface
Create and send an asynchronous HTTP PATCH request.
post()  : ResponseInterface
Create and send an HTTP POST request.
postAsync()  : PromiseInterface
Create and send an asynchronous HTTP POST request.
put()  : ResponseInterface
Create and send an HTTP PUT request.
putAsync()  : PromiseInterface
Create and send an asynchronous HTTP PUT request.
request()  : ResponseInterface
Create and send an HTTP request.
requestAsync()  : PromiseInterface
Create and send an asynchronous HTTP request.
send()  : ResponseInterface
Send an HTTP request.
sendAsync()  : PromiseInterface
Asynchronously send an HTTP request.
sendRequest()  : ResponseInterface
The HttpClient PSR (PSR-18) specify this method.
applyOptions()  : RequestInterface
Applies the array of request options to a request.
buildUri()  : UriInterface
canStringifyDeprecatedValue()  : bool
castDeprecatedHeaderOptionValues()  : array<int, string>
configureDefaults()  : void
Configures the default options for a client.
createBodyStream()  : StreamInterface
invalidBody()  : InvalidArgumentException
Return an InvalidArgumentException with pre-set message.
isProtocolVersionValid()  : bool
normalizeDeprecatedAuthOptionValues()  : void
normalizeDeprecatedIntegerOptionValues()  : void
normalizeDeprecatedNumericOptionValues()  : void
normalizeDeprecatedRequestOptionValues()  : array<string, mixed>
Normalize values that guzzlehttp/guzzle 8.0 rejects only after the corresponding 7.x deprecation has already been emitted.
normalizeDeprecatedStringOptionValues()  : void
normalizeDeprecatedTlsFileOptionValues()  : void
normalizeNonFiniteFloats()  : array<string|int, mixed>
Converts non-finite floats in the array to the strings PHP coerces them to, as implicit coercion of NAN emits a warning on PHP 8.5.
normalizeProtocolVersion()  : string
prepareDefaults()  : array<string|int, mixed>
Merges default options into the array.
shouldPreserveHost()  : bool
Whether to preserve an existing Host header when the URI changes.
stringifyDeprecatedValue()  : string
stringifyScalar()  : string
transfer()  : PromiseInterface
Transfers the given request and applies request options.
warnAboutInvalidAllowRedirectsOptionTypes()  : void
warnAboutInvalidAuthOptionTypes()  : void
warnAboutInvalidFormParamArray()  : bool
warnAboutInvalidFormParamTypes()  : void
warnAboutInvalidHeaderOptionTypes()  : void
warnAboutInvalidMultipartOptionTypes()  : void
warnAboutInvalidProtocolValues()  : void
warnAboutInvalidProxyOptionTypes()  : void
warnAboutInvalidRequestOptionTypes()  : void
warnAboutInvalidTlsFileOptionTypes()  : void
warnAboutRequestLevelHandler()  : void
warnIfPresentAndNotArray()  : void
warnIfPresentAndNotBool()  : void
warnIfPresentAndNotBoolOrInt()  : void
warnIfPresentAndNotBoolOrResource()  : void
warnIfPresentAndNotBoolOrString()  : void
warnIfPresentAndNotCallable()  : void
warnIfPresentAndNotInt()  : void
warnIfPresentAndNotNumber()  : void
warnIfPresentAndNotString()  : void
warnIfPresentAndNotStringArray()  : void
warnIfPresentAndNotStringOrNumber()  : void
warnInvalidRequestOptionType()  : void

Properties

$config

private array<string|int, mixed> $config

Default request options

Methods

__construct()

Clients accept an array of constructor parameters.

public __construct([array<string|int, mixed> $config = [] ]) : mixed

Here's an example of creating a client using a base_uri and an array of default request options to apply to each request:

$client = new Client([
    'base_uri'        => 'http://www.foo.com/1.0/',
    'timeout'         => 0,
    'allow_redirects' => false,
    'proxy'           => '192.168.16.1:10'
]);

Client configuration settings include the following options:

  • handler: (callable) Function that transfers HTTP requests over the wire. The function is called with a Psr7\Http\Message\RequestInterface and array of transfer options, and must return a GuzzleHttp\Promise\PromiseInterface that is fulfilled with a Psr7\Http\Message\ResponseInterface on success. If no handler is provided, a default handler will be created that enables all of the request options below by attaching all of the default middleware to the handler.
  • base_uri: (string|UriInterface) Base URI of the client that is merged into relative URIs. Can be a string or instance of UriInterface.
  • transport_sharing: (string|null) Transport sharing mode for the default handler. Accepts TransportSharing::* or null. Defaults to null.
  • max_host_connections: (int|null) Maximum concurrent connections per host, applied by the default CurlMultiHandler. The default stream fallback receives the cap as a marker only: it rejects enabled response streaming ("stream" => true) and does not limit overlapping buffered calls.
  • max_total_connections: (int|null) Maximum concurrent connections overall, applied by the default CurlMultiHandler. The default stream fallback receives the cap as a marker only: it rejects enabled response streaming ("stream" => true) and does not limit overlapping buffered calls.
  • multiplex: (string|null) Multiplexing::NONE to disable multiplexing on the default CurlMultiHandler; the value also becomes the default "multiplex" request option. Other Multiplexing::* values act as the default request option only.
  • **: any request option
Parameters
$config : array<string|int, mixed> = []

Client configuration settings.

Tags
see
RequestOptions

for a list of available request options.

delete()

Create and send an HTTP DELETE request.

public delete(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

deleteAsync()

Create and send an asynchronous HTTP DELETE request.

public deleteAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

get()

Create and send an HTTP GET request.

public get(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

getAsync()

Create and send an asynchronous HTTP GET request.

public getAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

getConfig()

Get a client configuration option.

public getConfig([string|null $option = null ]) : mixed

These options include default request options of the client, a "handler" (if utilized by the concrete client), and a "base_uri" if utilized by the concrete client.

Parameters
$option : string|null = null

The config option to retrieve.

head()

Create and send an HTTP HEAD request.

public head(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

headAsync()

Create and send an asynchronous HTTP HEAD request.

public headAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

patch()

Create and send an HTTP PATCH request.

public patch(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

patchAsync()

Create and send an asynchronous HTTP PATCH request.

public patchAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

post()

Create and send an HTTP POST request.

public post(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

postAsync()

Create and send an asynchronous HTTP POST request.

public postAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

put()

Create and send an HTTP PUT request.

public put(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Tags
throws
GuzzleException
Return values
ResponseInterface

putAsync()

Create and send an asynchronous HTTP PUT request.

public putAsync(string|UriInterface $uri[, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$uri : string|UriInterface

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply.

Return values
PromiseInterface

request()

Create and send an HTTP request.

public request(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : ResponseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well.

Parameters
$method : string

HTTP method.

$uri : string|UriInterface = ''

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply. See RequestOptions.

Tags
throws
GuzzleException
Return values
ResponseInterface

requestAsync()

Create and send an asynchronous HTTP request.

public requestAsync(string $method[, string|UriInterface $uri = '' ][, array<string|int, mixed> $options = [] ]) : PromiseInterface

Use an absolute path to override the base path of the client, or a relative path to append to the base path of the client. The URL can contain the query string as well. Use an array to provide a URL template and additional variables to use in the URL template expansion.

Parameters
$method : string

HTTP method

$uri : string|UriInterface = ''

URI object or string.

$options : array<string|int, mixed> = []

Request options to apply. See RequestOptions.

Return values
PromiseInterface

canStringifyDeprecatedValue()

private static canStringifyDeprecatedValue(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

castDeprecatedHeaderOptionValues()

private static castDeprecatedHeaderOptionValues(array<string|int, mixed> &$headers) : array<int, string>
Parameters
$headers : array<string|int, mixed>
Return values
array<int, string>

configureDefaults()

Configures the default options for a client.

private configureDefaults(array<string|int, mixed> $config) : void
Parameters
$config : array<string|int, mixed>

isProtocolVersionValid()

private static isProtocolVersionValid(string $version) : bool
Parameters
$version : string
Return values
bool

normalizeDeprecatedAuthOptionValues()

private static normalizeDeprecatedAuthOptionValues(array<string, mixed> &$options) : void
Parameters
$options : array<string, mixed>

normalizeDeprecatedIntegerOptionValues()

private static normalizeDeprecatedIntegerOptionValues(array<string, mixed> &$options) : void
Parameters
$options : array<string, mixed>

normalizeDeprecatedNumericOptionValues()

private static normalizeDeprecatedNumericOptionValues(array<string, mixed> &$options) : void
Parameters
$options : array<string, mixed>

normalizeDeprecatedRequestOptionValues()

Normalize values that guzzlehttp/guzzle 8.0 rejects only after the corresponding 7.x deprecation has already been emitted.

private static normalizeDeprecatedRequestOptionValues(array<string, mixed> $options) : array<string, mixed>
Parameters
$options : array<string, mixed>
Return values
array<string, mixed>

normalizeDeprecatedStringOptionValues()

private static normalizeDeprecatedStringOptionValues(array<string, mixed> &$options) : void
Parameters
$options : array<string, mixed>

normalizeDeprecatedTlsFileOptionValues()

private static normalizeDeprecatedTlsFileOptionValues(array<string, mixed> &$options, string $option) : void
Parameters
$options : array<string, mixed>
$option : string

normalizeNonFiniteFloats()

Converts non-finite floats in the array to the strings PHP coerces them to, as implicit coercion of NAN emits a warning on PHP 8.5.

private static normalizeNonFiniteFloats(array<string|int, mixed> $values, string $option) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>
$option : string
Return values
array<string|int, mixed>

normalizeProtocolVersion()

private static normalizeProtocolVersion(string|int|float $version) : string
Parameters
$version : string|int|float
Return values
string

prepareDefaults()

Merges default options into the array.

private prepareDefaults(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed>

Options to modify by reference

Return values
array<string|int, mixed>

shouldPreserveHost()

Whether to preserve an existing Host header when the URI changes.

private static shouldPreserveHost(RequestInterface $request) : bool

A header matching the current URI carries no explicit override and is regenerated after base URI resolution or IDN conversion. Other values are preserved as deliberate overrides, as PSR-7 requires.

Parameters
$request : RequestInterface
Return values
bool

stringifyDeprecatedValue()

private static stringifyDeprecatedValue(mixed $value) : string
Parameters
$value : mixed
Return values
string

stringifyScalar()

private static stringifyScalar(bool|float|int|string $value) : string
Parameters
$value : bool|float|int|string
Return values
string

warnAboutInvalidAllowRedirectsOptionTypes()

private static warnAboutInvalidAllowRedirectsOptionTypes(array<string|int, mixed> $allowRedirects) : void
Parameters
$allowRedirects : array<string|int, mixed>

warnAboutInvalidAuthOptionTypes()

private static warnAboutInvalidAuthOptionTypes(mixed $auth) : void
Parameters
$auth : mixed

warnAboutInvalidFormParamArray()

private static warnAboutInvalidFormParamArray(array<string|int, mixed> $values, string $path) : bool
Parameters
$values : array<string|int, mixed>
$path : string
Return values
bool

warnAboutInvalidFormParamTypes()

private static warnAboutInvalidFormParamTypes(mixed $value) : void
Parameters
$value : mixed

warnAboutInvalidHeaderOptionTypes()

private static warnAboutInvalidHeaderOptionTypes(mixed $headers) : void
Parameters
$headers : mixed

warnAboutInvalidMultipartOptionTypes()

private static warnAboutInvalidMultipartOptionTypes(mixed $multipart) : void
Parameters
$multipart : mixed

warnAboutInvalidProtocolValues()

private static warnAboutInvalidProtocolValues(array<string|int, mixed> $options, string $option[, string|null $path = null ]) : void
Parameters
$options : array<string|int, mixed>
$option : string
$path : string|null = null

warnAboutInvalidProxyOptionTypes()

private static warnAboutInvalidProxyOptionTypes(array<string|int, mixed> $options) : void
Parameters
$options : array<string|int, mixed>

warnAboutInvalidRequestOptionTypes()

private static warnAboutInvalidRequestOptionTypes(array<string|int, mixed> $options) : void
Parameters
$options : array<string|int, mixed>

warnAboutInvalidTlsFileOptionTypes()

private static warnAboutInvalidTlsFileOptionTypes(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnAboutRequestLevelHandler()

private static warnAboutRequestLevelHandler(array<string|int, mixed> $options) : void
Parameters
$options : array<string|int, mixed>

warnIfPresentAndNotArray()

private static warnIfPresentAndNotArray(array<string|int, mixed> $options, string $option, string $expected) : void
Parameters
$options : array<string|int, mixed>
$option : string
$expected : string

warnIfPresentAndNotBool()

private static warnIfPresentAndNotBool(array<string|int, mixed> $options, string $option[, string|null $path = null ]) : void
Parameters
$options : array<string|int, mixed>
$option : string
$path : string|null = null

warnIfPresentAndNotBoolOrInt()

private static warnIfPresentAndNotBoolOrInt(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnIfPresentAndNotBoolOrResource()

private static warnIfPresentAndNotBoolOrResource(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnIfPresentAndNotBoolOrString()

private static warnIfPresentAndNotBoolOrString(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnIfPresentAndNotCallable()

private static warnIfPresentAndNotCallable(array<string|int, mixed> $options, string $option[, string|null $path = null ][, string $since = '7.11' ]) : void
Parameters
$options : array<string|int, mixed>
$option : string
$path : string|null = null
$since : string = '7.11'

warnIfPresentAndNotInt()

private static warnIfPresentAndNotInt(array<string|int, mixed> $options, string $option[, string|null $path = null ][, string $since = '7.11' ]) : void
Parameters
$options : array<string|int, mixed>
$option : string
$path : string|null = null
$since : string = '7.11'

warnIfPresentAndNotNumber()

private static warnIfPresentAndNotNumber(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnIfPresentAndNotString()

private static warnIfPresentAndNotString(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnIfPresentAndNotStringArray()

private static warnIfPresentAndNotStringArray(array<string|int, mixed> $options, string $option, bool $nonEmpty[, string|null $path = null ]) : void
Parameters
$options : array<string|int, mixed>
$option : string
$nonEmpty : bool
$path : string|null = null

warnIfPresentAndNotStringOrNumber()

private static warnIfPresentAndNotStringOrNumber(array<string|int, mixed> $options, string $option) : void
Parameters
$options : array<string|int, mixed>
$option : string

warnInvalidRequestOptionType()

private static warnInvalidRequestOptionType(string $option, string $expected, mixed $value[, string $since = '7.11' ]) : void
Parameters
$option : string
$expected : string
$value : mixed
$since : string = '7.11'
On this page

Search results