- Getting Started
- API Reference
Clone this wiki locally
Use the Aerospike PHP client to build PHP applications to store and retrieve data from an Aerospike cluster.
The Aerospike PHP client is built on top of the Aerospike C client, as an extension for PHP version 7.0, or above.
This example shows how a client connects to the Aerospike cluster, creates a key, records and their bins, and reads the bin values.
// The cluster can be located by just one host $config = [ "hosts" => [ [ "addr" => "127.0.0.1", "port" => 3000 ]]]; // The new client connects and learns the cluster layout $db = new Aerospike($config); // records are identified as a (namespace, set, and primary-key) tuple $key = $db->initKey("infosphere", "characters", 1234); // the record and its bins are created and updated similar to an array $put_vals = [ "name" => "Scruffy", "Occupation" => "The Janitor" ]; $db->put($key, $put_vals); // record bins can hold complex types, such as arrays $update_vals = [ "quotes" => [ "I'm Scruffy. The janitor.", "I'm on break.", "Scruffy's gonna die like he lived."]]; $db->put($key, $update_vals); // read selected bins from a record $db->get($key, $record, ["name", "quotes"]); $db->close();
At the top of the data model is the namespace. This container has one set of policy rules for all data. Namespace is similar to the database concept in an RDBMS, only it is distributed across the cluster. A namespace is divided into sets, similar to RDBMS tables.
Bins are pairs of key-value data contained in records. These concepts are similar to columns of a row in RDBMS. Aerospike is schemaless. You don't have to define bins in advance.
Records are uniquely identified by their key. Sets have a primary index that contains the keys of all records in the set.
If you are using PHP 5.x, refer to Legacy PHP client that supports PHP 5.3, 5.4, 5.5, and 5.6.