final class Builder (View source)

Cluster builder allows fluent configuration of the cluster instance.

Methods

build()

Returns a Cluster Instance.

withDefaultConsistency(int $consistency)

Configures default consistency for all requests.

withDefaultPageSize(int|null $pageSize)

Configures default page size for all results.

withDefaultTimeout(float|null $timeout)

Configures default timeout for future resolution in blocking operations Set to null to disable (default).

withContactPoints(string ...$host)

Configures the initial endpoints. Note that the driver will automatically discover and connect to the rest of the cluster.

withPort(int $port)

Specify a different port to be used when connecting to the cluster.

withRoundRobinLoadBalancingPolicy()

Configures this cluster to use a round robin load balancing policy.

withDatacenterAwareRoundRobinLoadBalancingPolicy(string $localDatacenter, int $hostPerRemoteDatacenter, bool $useRemoteDatacenterForLocalConsistencies)

Configures this cluster to use a datacenter aware round robin load balancing policy.

withBlackListHosts(string $hosts)

Sets the blacklist hosts. Any host in the blacklist will be ignored and a connection will not be established. This is useful for ensuring that the driver will not connection to a predefied set of hosts.

withWhiteListHosts(string $hosts)

Sets the whitelist hosts. Any host not in the whitelist will be ignored and a connection will not be established. This policy is useful for ensuring that the driver will only connect to a predefined set of hosts.

withBlackListDCs(string $dcs)

Sets the blacklist datacenters. Any datacenter in the blacklist will be ignored and a connection will not be established to any host in those datacenters. This policy is useful for ensuring the driver will not connect to any host in a specific datacenter.

withWhiteListDCs(string $dcs)

Sets the whitelist datacenters. Any host not in a whitelisted datacenter will be ignored. This policy is useful for ensuring the driver will only connect to hosts in specific datacenters.

withTokenAwareRouting(bool $enabled)

Enable token aware routing.

withCredentials(string $username, string $password)

Configures plain-text authentication.

withConnectTimeout(float $timeout)

Timeout used for establishing TCP connections.

withRequestTimeout(float $timeout)

Timeout used for waiting for a response from a node.

withSSL(SSLOptions $options)

Set up ssl context.

withPersistentSessions(bool $enabled)

Enable persistent sessions and clusters.

withProtocolVersion(int $version)

Force the driver to use a specific binary protocol version.

withIOThreads(int $count)

Total number of IO threads to use for handling the requests.

withConnectionsPerHost(int $core, int $max)

Set the size of connection pools used by the driver. Pools are fixed when only $core is given, when a $max is specified as well, additional connections will be created automatically based on current load until the maximum number of connection has been reached. When request load goes down, extra connections are automatically cleaned up until only the core number of connections is left.

withReconnectInterval(float $interval)

Specify interval in seconds that the driver should wait before attempting to re-establish a closed connection.

withLatencyAwareRouting(bool $enabled)

Enables/disables latency-aware routing.

withTCPNodelay(bool $enabled)

Disables nagle algorithm for lower latency.

withTCPKeepalive(float|null $delay)

Enables/disables TCP keepalive.

withRetryPolicy(RetryPolicy $policy)

Configures the retry policy.

withTimestampGenerator(TimestampGenerator $generator)

Sets the timestamp generator.

withSchemaMetadata(bool $enabled)

Enables/disables Schema Metadata.

withHostnameResolution(bool $enabled)

Enables/disables Hostname Resolution.

withRandomizedContactPoints(bool $enabled)

Enables/disables Randomized Contact Points.

withConnectionHeartbeatInterval(float $interval)

Specify interval in seconds that the driver should wait before attempting to send heartbeat messages and control the amount of time the connection must be idle before sending heartbeat messages. This is useful for preventing intermediate network devices from dropping connections.

Details

Cluster build()

Returns a Cluster Instance.

Return Value

Cluster

Cluster instance

Builder withDefaultConsistency(int $consistency)

Configures default consistency for all requests.

Parameters

int $consistency

A consistency level, must be one of Cassandra::CONSISTENCY_* values

Return Value

Builder self

Builder withDefaultPageSize(int|null $pageSize)

Configures default page size for all results.

Set to null to disable paging altogether.

Parameters

int|null $pageSize

default page size

Return Value

Builder self

Builder withDefaultTimeout(float|null $timeout)

Configures default timeout for future resolution in blocking operations Set to null to disable (default).

Parameters

float|null $timeout

Timeout value in seconds, can be fractional

Return Value

Builder self

Builder withContactPoints(string ...$host)

Configures the initial endpoints. Note that the driver will automatically discover and connect to the rest of the cluster.

Parameters

string ...$host

one or more ip addresses or hostnames

Return Value

Builder self

Builder withPort(int $port)

Specify a different port to be used when connecting to the cluster.

Parameters

int $port

a number between 1 and 65535

Return Value

Builder self

Exceptions

InvalidArgumentException

Builder withRoundRobinLoadBalancingPolicy()

Configures this cluster to use a round robin load balancing policy.

Return Value

Builder self

Builder withDatacenterAwareRoundRobinLoadBalancingPolicy(string $localDatacenter, int $hostPerRemoteDatacenter, bool $useRemoteDatacenterForLocalConsistencies)

Configures this cluster to use a datacenter aware round robin load balancing policy.

Parameters

string $localDatacenter

Name of the local datacenter

int $hostPerRemoteDatacenter

Maximum number of hosts to try in remote datacenters

bool $useRemoteDatacenterForLocalConsistencies

Allow using hosts from remote datacenters to execute statements with local consistencies

Return Value

Builder self

Builder withBlackListHosts(string $hosts)

Sets the blacklist hosts. Any host in the blacklist will be ignored and a connection will not be established. This is useful for ensuring that the driver will not connection to a predefied set of hosts.

Parameters

string $hosts

A comma delimited list of addresses.

Return Value

Builder self

Builder withWhiteListHosts(string $hosts)

Sets the whitelist hosts. Any host not in the whitelist will be ignored and a connection will not be established. This policy is useful for ensuring that the driver will only connect to a predefined set of hosts.

Parameters

string $hosts

A comma delimited list of addresses.

Return Value

Builder self

Builder withBlackListDCs(string $dcs)

Sets the blacklist datacenters. Any datacenter in the blacklist will be ignored and a connection will not be established to any host in those datacenters. This policy is useful for ensuring the driver will not connect to any host in a specific datacenter.

Parameters

string $dcs

A comma delimited list of datacenters.

Return Value

Builder self

Builder withWhiteListDCs(string $dcs)

Sets the whitelist datacenters. Any host not in a whitelisted datacenter will be ignored. This policy is useful for ensuring the driver will only connect to hosts in specific datacenters.

Parameters

string $dcs

A comma delimited list of datacenters.

Return Value

Builder self

Builder withTokenAwareRouting(bool $enabled)

Enable token aware routing.

Parameters

bool $enabled

Whether to enable token aware routing (optional)

Return Value

Builder self

Builder withCredentials(string $username, string $password)

Configures plain-text authentication.

Parameters

string $username Username
string $password Password

Return Value

Builder self

Builder withConnectTimeout(float $timeout)

Timeout used for establishing TCP connections.

Parameters

float $timeout

Timeout value in seconds, can be fractional

Return Value

Builder self

Builder withRequestTimeout(float $timeout)

Timeout used for waiting for a response from a node.

Parameters

float $timeout

Timeout value in seconds, can be fractional

Return Value

Builder self

Builder withSSL(SSLOptions $options)

Set up ssl context.

Parameters

SSLOptions $options

a preconfigured ssl context

Return Value

Builder self

Builder withPersistentSessions(bool $enabled)

Enable persistent sessions and clusters.

Parameters

bool $enabled

whether to enable persistent sessions and clusters

Return Value

Builder self

Builder withProtocolVersion(int $version)

Force the driver to use a specific binary protocol version.

Apache Cassandra 1.2+ supports protocol version 1 Apache Cassandra 2.0+ supports protocol version 2 Apache Cassandra 2.1+ supports protocol version 3 Apache Cassandra 2.2+ supports protocol version 4

NOTE: Apache Cassandra 3.x supports protocol version 3 and 4 only

Parameters

int $version

The protocol version

Return Value

Builder self

Builder withIOThreads(int $count)

Total number of IO threads to use for handling the requests.

Note: number of io threads core connections per host <= total number of connections <= number of io threads max connections per host

Parameters

int $count

total number of threads.

Return Value

Builder self

Builder withConnectionsPerHost(int $core, int $max)

Set the size of connection pools used by the driver. Pools are fixed when only $core is given, when a $max is specified as well, additional connections will be created automatically based on current load until the maximum number of connection has been reached. When request load goes down, extra connections are automatically cleaned up until only the core number of connections is left.

Parameters

int $core

minimum connections to keep open to any given host

int $max

maximum connections to keep open to any given host

Return Value

Builder self

Builder withReconnectInterval(float $interval)

Specify interval in seconds that the driver should wait before attempting to re-establish a closed connection.

Parameters

float $interval

interval in seconds

Return Value

Builder self

Builder withLatencyAwareRouting(bool $enabled)

Enables/disables latency-aware routing.

Parameters

bool $enabled

whether to actually enable or disable the routing.

Return Value

Builder self

Builder withTCPNodelay(bool $enabled)

Disables nagle algorithm for lower latency.

Parameters

bool $enabled

whether to actually enable or disable nodelay.

Return Value

Builder self

Builder withTCPKeepalive(float|null $delay)

Enables/disables TCP keepalive.

Parameters

float|null $delay

The period of inactivity in seconds, after which the keepalive probe should be sent over the connection. If set to null, disables keepalive probing.

Return Value

Builder self

Builder withRetryPolicy(RetryPolicy $policy)

Configures the retry policy.

Parameters

RetryPolicy $policy

the retry policy to use.

Return Value

Builder self

Builder withTimestampGenerator(TimestampGenerator $generator)

Sets the timestamp generator.

Parameters

TimestampGenerator $generator

A timestamp generator that will be used to generate timestamps for statements.

Return Value

Builder self

Builder withSchemaMetadata(bool $enabled)

Enables/disables Schema Metadata.

If disabled this allows the driver to skip over retrieving and updating schema metadata, but it also disables the usage of token-aware routing and $session->schema() will always return an empty object. This can be useful for reducing the startup overhead of short-lived sessions.

Parameters

bool $enabled

whether the driver fetches and maintains schema metadata.

Return Value

Builder self

Builder withHostnameResolution(bool $enabled)

Enables/disables Hostname Resolution.

If enabled the driver will resolve hostnames for IP addresses using reverse IP lookup. This is useful for authentication (Kerberos) or encryption SSL services that require a valid hostname for verification.

Important: It's possible that the underlying C/C++ driver does not support hostname resolution. A PHP warning will be emitted if the driver does not support hostname resolution.

Parameters

bool $enabled

whether the driver uses hostname resolution.

Return Value

Builder self

Builder withRandomizedContactPoints(bool $enabled)

Enables/disables Randomized Contact Points.

If enabled this allows the driver randomly use contact points in order to evenly spread the load across the cluster and prevent hotspots/load spikes during notifications (e.g. massive schema change).

Note: This setting should only be disabled for debugging and testing.

Parameters

bool $enabled

whether the driver uses randomized contact points.

Return Value

Builder self

Builder withConnectionHeartbeatInterval(float $interval)

Specify interval in seconds that the driver should wait before attempting to send heartbeat messages and control the amount of time the connection must be idle before sending heartbeat messages. This is useful for preventing intermediate network devices from dropping connections.

Parameters

float $interval

interval in seconds (0 to disable heartbeat).

Return Value

Builder self