Cassandra\Cluster builder allows fluent configuration of the cluster instance.

See Also:

Methods

Cassandra\Cluster

build

( )

Returns a Cassandra\Cluster Instance.

Returns:
Type Details
Cassandra\Cluster

Cassandra\Cluster instance

Cluster\Builder

withDefaultConsistency

( int $consistency )

Configures default consistency for all requests.

Parameters:
Name Type Details
$consistency int

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

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDefaultPageSize

( int $pageSize )

Configures default page size for all results. Cassandra\Set to null to disable paging altogether.

Parameters:
Name Type Details
$pageSize int

default page size

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDefaultTimeout

( float $timeout )

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

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withContactPoints

( string $host )

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

Parameters:
Name Type Details
$host string

one or more ip addresses or hostnames

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withPort

( int $port )

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

Parameters:
Name Type Details
$port int

a number between 1 and 65535

Throws:
Type Details
Exception\InvalidArgumentException
Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withRoundRobinLoadBalancingPolicy

( )

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

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDatacenterAwareRoundRobinLoadBalancingPolicy

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

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

Parameters:
Name Type Details
$localDatacenter string

Name of the local datacenter

$hostPerRemoteDatacenter int

Maximum number of hosts to try in remote datacenters

$useRemoteDatacenterForLocalConsistencies bool

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

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withBlackListHosts

( string $hosts )

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

Parameters:
Name Type Details
$hosts string

A comma delimited list of addresses.

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$hosts string

A comma delimited list of addresses.

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$dcs string

A comma delimited list of datacenters.

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$dcs string

A comma delimited list of datacenters.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTokenAwareRouting

( bool $enabled )

Enable token aware routing.

Parameters:
Name Type Details
$enabled bool

Whether to enable token aware routing (optional)

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withCredentials

( string $username, string $password )

Configures plain-text authentication.

Parameters:
Name Type Details
$username string

Username

$password string

Password

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withConnectTimeout

( float $timeout )

Timeout used for establishing TCP connections.

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withRequestTimeout

( float $timeout )

Timeout used for waiting for a response from a node.

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withSSL

( Cassandra\SSLOptions $options )

Cassandra\Set up ssl context.

Parameters:
Name Type Details
$options Cassandra\SSLOptions

a preconfigured ssl context

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withPersistentSessions

( bool $enabled )

Enable persistent sessions and clusters.

Parameters:
Name Type Details
$enabled bool

whether to enable persistent sessions and clusters

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$version int

The protocol version

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$count int

total number of threads.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withConnectionsPerHost

( int $core, int $max )

Cassandra\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:
Name Type Details
$core int

minimum connections to keep open to any given host

$max int

maximum connections to keep open to any given host

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withReconnectInterval

( float $interval )

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

Parameters:
Name Type Details
$interval float

interval in seconds

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withLatencyAwareRouting

( bool $enabled )

Enables/disables latency-aware routing.

Parameters:
Name Type Details
$enabled bool

whether to actually enable or disable the routing.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTCPNodelay

( bool $enabled )

Disables nagle algorithm for lower latency.

Parameters:
Name Type Details
$enabled bool

whether to actually enable or disable nodelay.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTCPKeepalive

( float $delay )

Enables/disables TCP keepalive.

Parameters:
Name Type Details
$delay float

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

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withRetryPolicy

( Cluster\RetryPolicy $policy )

Configures the retry policy.

Parameters:
Name Type Details
$policy Cluster\RetryPolicy

the retry policy to use.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTimestampGenerator

( Cassandra\TimestampGenerator $generator )

Sets the timestamp generator.

Parameters:
Name Type Details
$generator Cassandra\TimestampGenerator

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

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withSchemaMetadata

( bool $enabled )

Enables/disables Cassandra\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:
Name Type Details
$enabled bool

whether the driver fetches and maintains schema metadata.

Returns:
Type Details
Cluster\Builder

self

Cluster\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.

Parameters:
Name Type Details
$enabled bool

whether the driver uses hostname resolution.

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$enabled bool

whether the driver uses randomized contact points.

Returns:
Type Details
Cluster\Builder

self

Cluster\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:
Name Type Details
$interval float

interval in seconds (0 to disable heartbeat).

Returns:
Type Details
Cluster\Builder

self