Documentation

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
$connect_error  : string
Cache for received connection errors.
$max_bytes  : int|bool
What's the maximum number of bytes we should keep?

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
accept_encoding()  : string
Retrieve the encodings we can accept
format_get()  : string
Format a URL given GET data

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

$connect_error

Cache for received connection errors.

private string $connect_error = ''

$max_bytes

What's the maximum number of bytes we should keep?

private int|bool $max_bytes = false

Byte count, or false if no limit.

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

Tags
codeCoverageIgnore
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

accept_encoding()

Retrieve the encodings we can accept

private static accept_encoding() : string
Return values
string

Accept-Encoding header value

format_get()

Format a URL given GET data

private static format_get(array<string|int, mixed> $url_parts, array<string|int, mixed>|object $data) : string
Parameters
$url_parts : array<string|int, mixed>

Array of URL parts as received from

$data : array<string|int, mixed>|object

Data to build query using, see

Return values
string

URL with data


        
On this page

Search results