Requests 2.0.13 API

Fsockopen
in package
implements Transport

FinalYes

fsockopen HTTP transport

Table of Contents

Interfaces

Transport
Base HTTP transport

Constants

SECOND_IN_MICROSECONDS  = 1000000
Second to microsecond conversion

Properties

$headers  : string
Raw HTTP data
$info  : array<string|int, mixed>
Stream metadata

Methods

connect_error_handler()  : mixed
Error handler for stream_socket_client()
request()  : string
Perform a request
request_multiple()  : array<string|int, mixed>
Send multiple requests simultaneously
test()  : bool
Self-test whether the transport can be used.
verify_certificate_from_context()  : bool
Verify the certificate against common name and subject alternative names

Constants

SECOND_IN_MICROSECONDS

Second to microsecond conversion

public int SECOND_IN_MICROSECONDS = 1000000

Properties

$headers

Raw HTTP data

public string $headers = ''

$info

Stream metadata

public array<string|int, mixed> $info

Associative array of properties, see

Methods

connect_error_handler()

Error handler for stream_socket_client()

public connect_error_handler(int $errno, string $errstr) : mixed
Parameters
$errno : int

Error number (e.g. E_WARNING)

$errstr : string

Error message

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
throws
InvalidArgument

When the passed $url argument is not a string or Stringable.

throws
InvalidArgument

When the passed $headers argument is not an array.

throws
InvalidArgument

When the passed $data parameter is not an array or string.

throws
InvalidArgument

When the passed $options argument is not an array.

throws
Exception

On failure to connect to socket (fsockopenerror)

throws
Exception

On socket timeout (timeout)

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 (array of 'url', 'headers', 'data', 'options') as per Transport::request()

$options : array<string|int, mixed>

Global options, see Requests::response() for documentation

Tags
throws
InvalidArgument

When the passed $requests argument is not an array or iterable object with array access.

throws
InvalidArgument

When the passed $options argument is not an array.

Return values
array<string|int, mixed>

Array of \WpOrg\Requests\Response objects (may contain \WpOrg\Requests\Exception or string responses as well)

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].

Return values
bool

Whether the transport can be used.

verify_certificate_from_context()

Verify the certificate against common name and subject alternative names

public verify_certificate_from_context(string $host, resource $context) : bool

Unfortunately, PHP doesn't check the certificate against the alternative names, leading things like 'https://www.github.com/' to be invalid. Instead

Parameters
$host : string

Host name to verify against

$context : resource

Stream context

Tags
link

RFC2818, Section 3.1

throws
Exception

On failure to connect via TLS (fsockopen.ssl.connect_error)

throws
Exception

On not obtaining a match for the host (fsockopen.ssl.no_match)

Return values
bool

        
On this page

Search results