Skip to content

Latest commit

 

History

History
98 lines (75 loc) · 3.94 KB

aerospike_construct.md

File metadata and controls

98 lines (75 loc) · 3.94 KB

Aerospike::__construct

Aerospike::__construct - constructs a new Aerospike object

Description

public Aerospike::__construct ( array $config [, boolean $persistent_connection = true [, array $options]] )

Aerospike::__construct() constructs an Aerospike object and connects to the cluster defined in config. The Aerospike::isConnected() method can be used to test whether the connection succeeded. If a config or connection error has occured, the Aerospike::error() and Aerospike::errorno() methods can be used to inspect it.

In a multiprocess context such as a web server, the class instance should be configured to use persistent connections. This allows for reduced overhead, saving on discovery of the cluster topology, fetching its partition map, and on opening connections to the nodes.

Parameters

config an array holding the cluster connection information. One node or more (for failover) may be defined. Once a connection is established to a node of the Aerospike DB the client will retrieve the full list of nodes in the cluster and manage its connections to them.

  • hosts an array of host data
    • addr hostname or IP of the node
    • port
  • user
  • pass
  • shm optional shared-memory cluster tending parameters. Shared-memory cluster tending is enabled if an array (even an empty one) is provided.
    • shm_key explicitly sets the shm key for the cluster. It is otherwise implicitly evaluated per unique hostname, and can be inspected with shmKey(). (default: 0xA5000000)
    • shm_max_nodes maximum number of nodes allowed. Pad so new nodes can be added without configuration changes (default: 16)
    • shm_max_namespaces maximum number of namespaces allowed (default: 8)
    • shm_takeover_threshold_sec take over tending if the cluster hasn't been checked for this many seconds (default: 30)
  • max_threads (default: 300)
  • thread_pool_size (default: 16)
  • compression_threshold client will compress records larger than this value for transport (default: 0)

persistent_connection whether the connections will persist between requests.

options including

See Also

The following only apply to instances created with non-persistent connections:

Examples

<?php

$config = [
  "hosts" => [
    ["addr" => "localhost", "port" => 3000]
  ],
  "shm" => []
];
$opts = [Aerospike::OPT_POLICY_KEY => Aerospike::POLICY_KEY_SEND];
$client = new Aerospike($config, true, $opts);
if (!$client->isConnected()) {
   echo "Aerospike failed to connect[{$client->errorno()}]: {$client->error()}\n";
   exit(1);
}

?>

On error we expect to see:

Aerospike failed to connect[-1]: Unable to connect to server

See Also