Class rex_socket

Class for sockets.

Example:

try {
    $socket = rex_socket::factory('www.example.com');
    $socket->setPath('/url/to/my/resource?param=1');
    $response = $socket->doGet();
    if($response->isOk()) {
        $body = $response->getBody();
    }
} catch(rex_socket_exception $e) {
    // error message: $e->getMessage()
}

Direct known subclasses

rex_socket_proxy

Package: redaxo\core
Author: gharlan
Located at redaxo/src/core/lib/util/socket/socket.php

Methods summary

protected
# __construct( string $host, integer $port = 80, boolean $ssl = false )

Constructor.

public static static
# factory( string $host, integer $port = 80, boolean $ssl = false )

Factory method.

public static static
# factoryUrl( string $url )

Creates a socket by a full URL.

public mixed
# setPath( string $path )

Sets the path.

public mixed
# addHeader( string $key, string $value )

Adds a header to the current request.

public mixed
# addBasicAuthorization( string $user, string $password )

Adds the basic authorization header to the current request.

public mixed
# setTimeout( integer $timeout )

Sets the timeout for the connection.

public mixed
# followRedirects( false|integer $redirects )

Sets number of redirects that should be followed automatically.

public rex_socket_response
# doGet( )

Makes a GET request.

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

Makes a POST request.

public rex_socket_response
# doDelete( )

Makes a DELETE request.

public rex_socket_response
# doRequest( string $method, string|callable $data = '' )

Makes a request.

protected
# openConnection( )

Opens the socket connection.

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

Writes a request to the opened connection.

protected static array
# parseUrl( string $url )

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

Properties summary

protected mixed $host
protected mixed $port
protected mixed $ssl
protected string $path
#'/'
protected integer $timeout
#15
protected boolean $followRedirects
#false
protected array $headers
#[]
protected mixed $stream