GridGain Quick Start Guide for PHP
This chapter explains system requirements for running GridGain and how to install GridGain, start a cluster, and run a simple Hello World example using a thin client for PHP.
Thin Client is a lightweight GridGain connection mode. It does not participate in cluster, never holds any data, or performs computations. All it does is establish a socket connection to an individual GridGain node and perform all operations through that node.
Since GridGain is built on top of Apache Ignite, GridGain reuses Ignite’s system properties, environment properties, startup scripts, etc. wherever possible.
Prerequisites
GridGain was officially tested on:
JDK |
Oracle JDK 8, 11 or 17, Open JDK 8, 11 or 17, IBM JDK 8, 11 or 17 |
OS |
Linux (any flavor), Mac OSX (10.6 and up), Windows (XP and up), Windows Server (2008 and up), Oracle Solaris, z/OS |
ISA |
x86, x64, SPARC, PowerPC |
Network |
No restrictions (10G recommended) |
and:
PHP |
Version 7.2 or higher and Composer Dependency Manager. PHP Multibyte String extension. Depending on your PHP configuration, you may need to additionally install/configure it. |
Installing GridGain
GridGain is available in three editions: Community Edition (CE), Enterprise Edition (EE) and Ultimate Edition (UE). For this example, we’ll use the GridGain CE, which is distributed as binary, docker, and cloud images, and via RPM/DEB. This chapter explains how to install the GridGain CE binary distribution.
To get started with the GridGain CE binary distribution:
-
Download the GridGain binary as a zip archive.
-
Unzip the zip archive into the installation folder in your system.
-
Move the
ignite-rest-http
folder from{gridgain}/libs/optional
to{gridgain}/libs
to enable the Ignite REST library for the cluster. The library is used by GridGain Web Console for cluster management and monitoring needs. -
(Optional) Enable required modules.
-
(Optional) Set the
IGNITE_HOME
environment variable or Windows PATH to point to the installation folder and make sure there is no trailing/
(or\
for Windows) in the path.
Once that’s done, install GridGain PHP Thin Client as a Composer package using the command below:
composer require gridgain/gridgain-client
To use the client in your application, include the vendor/autoload.php
file, generated by Composer, to your source code, eg.
require_once __DIR__ . '/vendor/autoload.php';
You’re almost ready to run your first application.
Starting a GridGain Node
Before connecting to GridGain from the PHP thin client, you must start at least one GridGain cluster node.
You can start a GridGain node from the command line using the default configuration or by passing a custom configuration file. You can start as many nodes as you like and they will all automatically discover each other.
Navigate into the bin
folder of GridGain installation directory from the command shell. Your command might look like this:
cd {gridgain}/bin/
cd {gridgain}\bin\
Start a node with a custom configuration file that is passed as a parameter to ignite.sh|bat
like this:
./ignite.sh ../examples/config/example-ignite.xml
ignite.bat ..\examples\config\example-ignite.xml
You will see output similar to this:
[08:53:45] Ignite node started OK (id=7b30bc8e) [08:53:45] Topology snapshot [ver=1, locNode=7b30bc8e, servers=1, clients=0, state=ACTIVE, CPUs=4, offheap=1.6GB, heap=2.0GB]
Open another tab from your command shell and run the same command again:
./ignite.sh ../examples/config/example-ignite.xml
ignite.bat ..\examples\config\example-ignite.xml
Check the Topology snapshot
line in the output.
Now you have a cluster of two server nodes with more CPUs and RAM available cluster-wide:
[08:54:34] Ignite node started OK (id=3a30b7a4) [08:54:34] Topology snapshot [ver=2, locNode=3a30b7a4, servers=2, clients=0, state=ACTIVE, CPUs=4, offheap=3.2GB, heap=4.0GB]
Running Your First GridGain Application
Once at least one node is started, you can use the GridGain PHP Thin
Client to perform cache operations. Archive installation of PHP Thin
Client includes several ready-to-run PHP examples in the
{client_dir}/examples
directory. Here is example how to run one of them:
cd {client_dir}/examples
php CachePutGetExample.php
cd {client_dir}\examples
php CachePutGetExample.php
Assuming that the server node is running locally, and that you have completed
all of the pre-requisites listed above, here is a very simple HelloWorld
example that puts and gets values from the cache. Note the require_once
line
— make sure the path is correct. If you followed the instructions above, and
if you place this hello world example in your examples folder, it should work.
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Apache\Ignite\Client;
use Apache\Ignite\ClientConfiguration;
use Apache\Ignite\Type\ObjectType;
use Apache\Ignite\Cache\CacheEntry;
use Apache\Ignite\Exception\ClientException;
function performCacheKeyValueOperations(): void
{
$client = new Client();
try {
$client->connect(new ClientConfiguration('127.0.0.1:10800'));
$cache = $client->getOrCreateCache('myCache')->
setKeyType(ObjectType::INTEGER);
// put and get value
$cache->put(1, 'Hello World');
$value = $cache->get(1);
echo($value);
} catch (ClientException $e) {
echo($e->getMessage());
} finally {
$client->disconnect();
}
}
performCacheKeyValueOperations();
Next Steps
From here, you may want to:
-
Read more about using GridGain
-
Use [Using GridGain Web Console] to monitor your cluster
-
Explore the additional examples included with GridGain
© 2023 GridGain Systems, Inc. All Rights Reserved. Privacy Policy | Legal Notices. GridGain® is a registered trademark of GridGain Systems, Inc.
Apache, Apache Ignite, the Apache feather and the Apache Ignite logo are either registered trademarks or trademarks of The Apache Software Foundation.