Binary Types

❗️

This is a legacy Apache Ignite documentation

The new documentation is hosted here: https://ignite.apache.org/docs/latest/

The PHP thin client supports all operations and types from the Binary Client Protocol except the following not-applicable features:

  • OP_REGISTER_BINARY_TYPE_NAME and OP_GET_BINARY_TYPE_NAME operations are not supported.
  • Filter object for OP_QUERY_SCAN operation is not supported. OP_QUERY_SCAN operation itself is supported.
  • It is not possible to register a new Ignite Enum type. Reading and writing items of the existing Ignite Enum types are supported.
  • Raw data is not supported in the complex objects.

The following example shows how to put/get Complex Objects and Binary Objects:

use Apache\Ignite\Client; use Apache\Ignite\ClientConfiguration; use Apache\Ignite\Type\ObjectType; use Apache\Ignite\Type\ComplexObjectType; use Apache\Ignite\Exception\ClientException; class Person { public $id; public $name; public $salary; public function __construct(int $id = 0, string $name = null, float $salary = 0) { $this->id = $id; $this->name = $name; $this->salary = $salary; } } function putGetComplexAndBinaryObjects(): void { $client = new Client(); try { $client->connect(new ClientConfiguration('127.0.0.1:10800')); $cache = $client->getOrCreateCache('myPersonCache')-> setKeyType(ObjectType::INTEGER); // Complex Object type for PHP Person class instances $personComplexObjectType = (new ComplexObjectType())-> setFieldType('id', ObjectType::INTEGER); // set cache key and value types $cache->setKeyType(ObjectType::INTEGER)-> setValueType($personComplexObjectType); // put Complex Objects to the cache $cache->put(1, new Person(1, 'John Doe', 1000)); $cache->put(2, new Person(2, 'Jane Roe', 2000)); // get Complex Object, returned value is an instance of Person class $person = $cache->get(1); print_r($person); // new CacheClient instance of the same cache to operate with BinaryObjects $binaryCache = $client->getCache('myPersonCache')-> setKeyType(ObjectType::INTEGER); // get Complex Object from the cache in a binary form, returned value is an instance of BinaryObject class $binaryPerson = $binaryCache->get(2); echo('Binary form of Person:' . PHP_EOL); foreach ($binaryPerson->getFieldNames() as $fieldName) { $fieldValue = $binaryPerson->getField($fieldName); echo($fieldName . ' : ' . $fieldValue . PHP_EOL); } // modify Binary Object and put it to the cache $binaryPerson->setField('id', 3, ObjectType::INTEGER)-> setField('name', 'Mary Major'); $binaryCache->put(3, $binaryPerson); // get Binary Object from the cache and convert it to PHP object $binaryPerson = $binaryCache->get(3); print_r($binaryPerson->toObject($personComplexObjectType)); $client->destroyCache('myPersonCache'); } catch (ClientException $e) { echo($e->getMessage()); } finally { $client->disconnect(); } } putGetComplexAndBinaryObjects();

📘

PHP example files

PHP thin client contains fully workable examples to demonstrate the behavior of the client.


close