Skip to content
Mira Dytko edited this page Aug 4, 2022 · 10 revisions

Introduction - PHP Client

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.

Code

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();

Data Model

At the top of the data model is the namespace container with one set of policy rules for all its data. This is similar to the database concept in an RDBMS, only the Aerospike database distributes the data across the cluster. Namespaces are subdivided into sets, which are similar to RDBMS tables.

Bins store the record data. The data type of the bin is set by the value of the data it contains. Multiple bins and data types can be stored in a single record. Aerospike is schema-less. There is no need 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.

Legacy PHP Client

If you are using PHP 5.x, refer to Legacy PHP client that supports PHP 5.3, 5.4, 5.5, and 5.6.

Getting Started