class SocketClient extends AbstractHTTPClient (View source)

This class uses a custom HTTP client, which may have more bugs then the default PHP HTTP clients, but supports keep alive connections without any extension dependencies.

Properties

protected array $options CouchDB connection options. from AbstractHTTPClient
protected resource $connection Connection pointer for connections, once keep alive is working on the CouchDb side.

Methods

__construct(string $host = 'localhost', int $port = 5984, string $username = null, string $password = null, string $ip = null, bool $ssl = false, string $path = null, int $timeout = 10, array $headers = [])

Construct a CouchDB connection.

void
setOption(string $option, mixed $value)

Set option value.

array
getOptions()

Get the connection options.

resource
getConnection(string $method, string $path, string $data = null, array $headers = [])

Return the socket after setting up the connection to server and writing the headers. The returned resource can later be used to read and write data in chunks. These should be done without much delay as the connection might get closed.

void
checkConnection()

Check for server connection.

string
buildRequest(string $method, string $path, string $data = null, array $headers = [])

Build a HTTP 1.1 request.

request(string $method, string $path, string $data = null, bool $raw = false, array $headers = [])

Perform a request to the server and return the result.

Details

AbstractHTTPClient __construct(string $host = 'localhost', int $port = 5984, string $username = null, string $password = null, string $ip = null, bool $ssl = false, string $path = null, int $timeout = 10, array $headers = [])

Construct a CouchDB connection.

Construct a CouchDB connection from basic connection parameters for one given database.

Parameters

string $host
int $port
string $username
string $password
string $ip
bool $ssl
string $path
int $timeout
array $headers

Return Value

AbstractHTTPClient

void setOption(string $option, mixed $value)

Set option value.

Set the value for an connection option. Throws an InvalidArgumentException for unknown options.

Parameters

string $option
mixed $value

Return Value

void

Exceptions

InvalidArgumentException

array getOptions()

Get the connection options.

Return Value

array

resource getConnection(string $method, string $path, string $data = null, array $headers = [])

Return the socket after setting up the connection to server and writing the headers. The returned resource can later be used to read and write data in chunks. These should be done without much delay as the connection might get closed.

Parameters

string $method
string $path
string $data
array $headers

Return Value

resource

Exceptions

HTTPException

protected void checkConnection()

Check for server connection.

Checks if the connection already has been established, or tries to establish the connection, if not done yet.

Return Value

void

Exceptions

HTTPException

protected string buildRequest(string $method, string $path, string $data = null, array $headers = [])

Build a HTTP 1.1 request.

Build the HTTP 1.1 request headers from the given input.

Parameters

string $method
string $path
string $data
array $headers

Return Value

string

Response request(string $method, string $path, string $data = null, bool $raw = false, array $headers = [])

Perform a request to the server and return the result.

Perform a request to the server and return the result converted into a Response object. If you do not expect a JSON structure, which could be converted in such a response object, set the forth parameter to true, and you get a response object returned, containing the raw body.

Parameters

string $method
string $path
string $data
bool $raw
array $headers

Return Value

Response