Documentation

CurlHandle
in package

Immutable wrapper for a cURL handle

Table of Contents

Constants

BODY_AS_STRING  = 'body_as_string'
DEBUG  = 'debug'
PROGRESS  = 'progress'

Properties

$errorNo  : int
$handle  : resource
$options  : Collection

Methods

__construct()  : mixed
Construct a new CurlHandle object that wraps a cURL handle
__destruct()  : mixed
Destructor
close()  : mixed
Close the curl handle
factory()  : CurlHandle
Factory method to create a new curl handle based on an HTTP request.
getError()  : string
Get the last error that occurred on the cURL handle
getErrorNo()  : int
Get the last error number that occurred on the cURL handle
getHandle()  : resource|null
Get the wrapped curl handle
getInfo()  : array<string|int, mixed>|mixed
Get cURL curl_getinfo data
getOptions()  : Collection
Get the cURL setopt options of the handle. Changing values in the return object will have no effect on the curl handle after it is created.
getStderr()  : string|resource|null
Get the stderr output
getUrl()  : Url
Get the URL that this handle is connecting to
isAvailable()  : bool
Check if the handle is available and still OK
parseCurlConfig()  : array<string|int, mixed>
Parse the config and replace curl.* configurators into the constant based values so it can be used elsewhere
setErrorNo()  : CurlHandle
Set the curl error number
updateRequestFromTransfer()  : mixed
Update a request based on the log messages of the CurlHandle

Constants

BODY_AS_STRING

public mixed BODY_AS_STRING = 'body_as_string'

Properties

$errorNo

protected int $errorNo = CURLE_OK

CURLE_* error

$handle

protected resource $handle

Curl resource handle

Methods

__construct()

Construct a new CurlHandle object that wraps a cURL handle

public __construct(resource $handle, Collection|array<string|int, mixed> $options) : mixed
Parameters
$handle : resource

Configured cURL handle resource

$options : Collection|array<string|int, mixed>

Curl options to use with the handle

Tags
throws
InvalidArgumentException

__destruct()

Destructor

public __destruct() : mixed

close()

Close the curl handle

public close() : mixed

factory()

Factory method to create a new curl handle based on an HTTP request.

public static factory(RequestInterface $request) : CurlHandle

There are some helpful options you can set to enable specific behavior:

  • debug: Set to true to enable cURL debug functionality to track the actual headers sent over the wire.
  • progress: Set to true to enable progress function callbacks.
Parameters
$request : RequestInterface

Request

Tags
throws
RuntimeException
Return values
CurlHandle

getError()

Get the last error that occurred on the cURL handle

public getError() : string
Return values
string

getErrorNo()

Get the last error number that occurred on the cURL handle

public getErrorNo() : int
Return values
int

getHandle()

Get the wrapped curl handle

public getHandle() : resource|null
Return values
resource|null

Returns the cURL handle or null if it was closed

getInfo()

Get cURL curl_getinfo data

public getInfo([int $option = null ]) : array<string|int, mixed>|mixed
Parameters
$option : int = null

Option to retrieve. Pass null to retrieve all data as an array.

Return values
array<string|int, mixed>|mixed

getOptions()

Get the cURL setopt options of the handle. Changing values in the return object will have no effect on the curl handle after it is created.

public getOptions() : Collection
Return values
Collection

getStderr()

Get the stderr output

public getStderr([bool $asResource = false ]) : string|resource|null
Parameters
$asResource : bool = false

Set to TRUE to get an fopen resource

Return values
string|resource|null

getUrl()

Get the URL that this handle is connecting to

public getUrl() : Url
Return values
Url

isAvailable()

Check if the handle is available and still OK

public isAvailable() : bool
Return values
bool

parseCurlConfig()

Parse the config and replace curl.* configurators into the constant based values so it can be used elsewhere

public static parseCurlConfig(array<string|int, mixed>|Collection $config) : array<string|int, mixed>
Parameters
$config : array<string|int, mixed>|Collection

The configuration we want to parse

Return values
array<string|int, mixed>

setErrorNo()

Set the curl error number

public setErrorNo(int $error) : CurlHandle
Parameters
$error : int

Error number to set

Return values
CurlHandle

updateRequestFromTransfer()

Update a request based on the log messages of the CurlHandle

public updateRequestFromTransfer(RequestInterface $request) : mixed
Parameters
$request : RequestInterface

Request to update

✖ Error 404 while fetching file: 
On this page

Search results