Properties

$host

$host : string

Type

string

$port

$port : int

Type

int

$ssl

$ssl : bool

Type

bool

$path

$path : string

Type

string

$timeout

$timeout : int

Type

int

$followRedirects

$followRedirects : false|int

Type

false|int

$headers

$headers : array<string,string>

Type

array

$stream

$stream

$destinationHost

$destinationHost : string

Type

string

$destinationPort

$destinationPort : int

Type

int

$destinationSsl

$destinationSsl : bool

Type

bool

Methods

factory()

factory(string  $host, int  $port = 80, bool  $ssl = false) : static

Factory method.

Parameters

string $host

Host name

int $port

Port number

bool $ssl

SSL flag

Returns

static —

Socket instance

factoryUrl()

factoryUrl(string  $url) : static

Creates a socket by a full URL.

Parameters

string $url

URL

Throws

\rex_socket_exception

Returns

static —

Socket instance

setPath()

setPath(string  $path) : $this

Sets the path.

Parameters

string $path

Returns

$this —

Current socket

addHeader()

addHeader(string  $key, string  $value) : $this

Adds a header to the current request.

Parameters

string $key
string $value

Returns

$this —

Current socket

addBasicAuthorization()

addBasicAuthorization(string  $user, string  $password) : $this

Adds the basic authorization header to the current request.

Parameters

string $user
string $password

Returns

$this —

Current socket

setTimeout()

setTimeout(int  $timeout) : $this

Sets the timeout for the connection.

Parameters

int $timeout

Timeout

Returns

$this —

Current socket

followRedirects()

followRedirects(false|int  $redirects) : $this

Sets number of redirects that should be followed automatically.

The method only affects GET requests.

Parameters

false|int $redirects

Number of max redirects

Returns

$this —

Current socket

doGet()

doGet() : \rex_socket_response

Makes a GET request.

Throws

\rex_socket_exception

Returns

\rex_socket_response —

Response

doPost()

doPost(string|array|callable  $data = '', array  $files = []) : \rex_socket_response

Makes a POST request.

Parameters

string|array|callable $data

Body data as string or array (POST parameters) or a callback for writing the body

array $files

Files array, e.g. array('myfile' => array('path' => $path, 'type' => 'image/png'))

Throws

\rex_socket_exception

Returns

\rex_socket_response —

Response

doDelete()

doDelete() : \rex_socket_response

Makes a DELETE request.

Throws

\rex_socket_exception

Returns

\rex_socket_response —

Response

doRequest()

doRequest(string  $method, string|callable  $data = '') : \rex_socket_response

Makes a request.

Parameters

string $method

HTTP method, e.g. "GET"

string|callable $data

Body data as string or a callback for writing the body

Throws

\InvalidArgumentException

Returns

\rex_socket_response —

Response

setDestination()

setDestination(string  $host, int  $port = 80, bool  $ssl = false) : $this

Sets the destination.

Parameters

string $host

Host name

int $port

Port number

bool $ssl

SSL flag

Returns

$this —

Current socket

setDestinationUrl()

setDestinationUrl(string  $url) : $this

Sets the destination by a full URL.

Parameters

string $url

Full URL

Returns

$this —

Current socket

__construct()

__construct(string  $host, int  $port = 80, bool  $ssl = false) : mixed

Constructor.

Parameters

string $host

Host name

int $port

Port number

bool $ssl

SSL flag

Returns

mixed —

openConnection()

openConnection() : mixed

Opens the socket connection.

Returns

mixed —

writeRequest()

writeRequest(string  $method, string  $path, array  $headers = [], string|callable  $data = '') : \rex_socket_response

Writes a request to the opened connection.

Parameters

string $method

HTTP method, e.g. "GET"

string $path

Path

array $headers

Headers

string|callable $data

Body data as string or a callback for writing the body

Throws

\rex_socket_exception

Returns

\rex_socket_response —

Response

parseUrl()

parseUrl(string  $url) : array

Parses a full URL and returns an array with the keys "host", "port", "ssl" and "path".

Parameters

string $url

Full URL

Throws

\rex_socket_exception

Returns

array —

URL parts