Curl
in package
implements
Transport
cURL HTTP transport
Table of Contents
Interfaces
- Transport
- Base HTTP transport
Constants
- CURL_7_10_5 = 0x70a05
- CURL_7_16_2 = 0x71002
Properties
- $headers : string
- Raw HTTP data
- $info : array<string|int, mixed>
- Information on the current request
- $response_data : string
- Raw body data
- $version : int
- cURL version number
- $done_headers : bool
- Have we finished the headers yet?
- $handle : resource|CurlHandle
- cURL handle
- $hooks : Hooks
- Hook dispatcher instance
- $response_byte_limit : int|bool
- What's the maximum number of bytes we should keep?
- $response_bytes : int
- How many bytes are in the response body?
- $stream_handle : resource
- If streaming to a file, keep the file pointer
Methods
- __construct() : mixed
- Constructor
- __destruct() : mixed
- Destructor
- get_subrequest_handle() : resource|CurlHandle
- Get the cURL handle for use in a multi-request
- process_response() : string|false
- Process a response
- request() : string
- Perform a request
- request_multiple() : array<string|int, mixed>
- Send multiple requests simultaneously
- stream_body() : int
- Collect data as it's received
- stream_headers() : int
- Collect the headers as they are received
- test() : bool
- Self-test whether the transport can be used.
- format_get() : string
- Format a URL given GET data
- get_expect_header() : string
- Get the correct "Expect" header for the given request data.
- setup_handle() : mixed
- Setup the cURL handle for the given data
Constants
CURL_7_10_5
public
mixed
CURL_7_10_5
= 0x70a05
CURL_7_16_2
public
mixed
CURL_7_16_2
= 0x71002
Properties
$headers
Raw HTTP data
public
string
$headers
= ''
$info
Information on the current request
public
array<string|int, mixed>
$info
$response_data
Raw body data
public
string
$response_data
= ''
$version
cURL version number
public
int
$version
$done_headers
Have we finished the headers yet?
private
bool
$done_headers
= false
$handle
cURL handle
private
resource|CurlHandle
$handle
Resource in PHP < 8.0, Instance of CurlHandle in PHP >= 8.0.
$hooks
Hook dispatcher instance
private
Hooks
$hooks
$response_byte_limit
What's the maximum number of bytes we should keep?
private
int|bool
$response_byte_limit
Byte count, or false if no limit.
$response_bytes
How many bytes are in the response body?
private
int
$response_bytes
$stream_handle
If streaming to a file, keep the file pointer
private
resource
$stream_handle
Methods
__construct()
Constructor
public
__construct() : mixed
__destruct()
Destructor
public
__destruct() : mixed
get_subrequest_handle()
Get the cURL handle for use in a multi-request
public
& get_subrequest_handle(string $url, array<string|int, mixed> $headers, string|array<string|int, mixed> $data, array<string|int, mixed> $options) : resource|CurlHandle
Parameters
- $url : string
-
URL to request
- $headers : array<string|int, mixed>
-
Associative array of request headers
- $data : string|array<string|int, mixed>
-
Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
- $options : array<string|int, mixed>
-
Request options, see Requests::response() for documentation
Return values
resource|CurlHandle —Subrequest's cURL handle
process_response()
Process a response
public
process_response(string $response, array<string|int, mixed> $options) : string|false
Parameters
- $response : string
-
Response data from the body
- $options : array<string|int, mixed>
-
Request options
Tags
Return values
string|false —HTTP response data including headers. False if non-blocking.
request()
Perform a request
public
request(string|Stringable $url[, array<string|int, mixed> $headers = [] ][, string|array<string|int, mixed> $data = [] ][, array<string|int, mixed> $options = [] ]) : string
Parameters
- $url : string|Stringable
-
URL to request
- $headers : array<string|int, mixed> = []
-
Associative array of request headers
- $data : string|array<string|int, mixed> = []
-
Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
- $options : array<string|int, mixed> = []
-
Request options, see Requests::response() for documentation
Tags
Return values
string —Raw HTTP result
request_multiple()
Send multiple requests simultaneously
public
request_multiple(array<string|int, mixed> $requests, array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $requests : array<string|int, mixed>
-
Request data
- $options : array<string|int, mixed>
-
Global options
Tags
Return values
array<string|int, mixed> —Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)
stream_body()
Collect data as it's received
public
stream_body(resource|CurlHandle $handle, string $data) : int
Parameters
- $handle : resource|CurlHandle
-
cURL handle
- $data : string
-
Body data
Tags
Return values
int —Length of provided data
stream_headers()
Collect the headers as they are received
public
stream_headers(resource|CurlHandle $handle, string $headers) : int
Parameters
- $handle : resource|CurlHandle
-
cURL handle
- $headers : string
-
Header string
Return values
int —Length of provided header
test()
Self-test whether the transport can be used.
public
static test([array<string, bool> $capabilities = [] ]) : bool
The available capabilities to test for can be found in Capability.
Parameters
- $capabilities : array<string, bool> = []
-
Optional. Associative array of capabilities to test against, i.e.
['<capability>' => true]
.
Tags
Return values
bool —Whether the transport can be used.
format_get()
Format a URL given GET data
private
static format_get(string $url, array<string|int, mixed>|object $data) : string
Parameters
Return values
string —URL with data
get_expect_header()
Get the correct "Expect" header for the given request data.
private
get_expect_header(string|array<string|int, mixed> $data) : string
Parameters
- $data : string|array<string|int, mixed>
-
Data to send either as the POST body, or as parameters in the URL for a GET/HEAD.
Return values
string —The "Expect" header.
setup_handle()
Setup the cURL handle for the given data
private
setup_handle(string $url, array<string|int, mixed> $headers, string|array<string|int, mixed> $data, array<string|int, mixed> $options) : mixed
Parameters
- $url : string
-
URL to request
- $headers : array<string|int, mixed>
-
Associative array of request headers
- $data : string|array<string|int, mixed>
-
Data to send either as the POST body, or as parameters in the URL for a GET/HEAD
- $options : array<string|int, mixed>
-
Request options, see Requests::response() for documentation