Skip to content

Instantly share code, notes, and snippets.

@vharish
Last active July 25, 2018 06:56
Show Gist options
  • Save vharish/f95501c1c57ecf3ba07bc7725cc49fbc to your computer and use it in GitHub Desktop.
Save vharish/f95501c1c57ecf3ba07bc7725cc49fbc to your computer and use it in GitHub Desktop.
PHP Apache Ignite ODBC integration on Ubuntu

Apache Ignite setup for php on ubuntu

Download and install

Binary is good enough if you do not want to build from source. You can find the installation instructions here.

Build and install the driver

Check if the driver has any unresolved dependency using ldd.

ldd /usr/local/lib/libignite-odbc.so

Check for the config in /etc/odbc.ini and /etc/odbcinst.ini

odbcinst.ini contains the driver info. The name defined in this is used in the application. Check if the driver definition is correct.

odbc.ini contains the dns info. It could be empty. The DNS can be defined here if necessary.

Post Installation Checklist

JAVA_HOME

This should point to the java home directory. For linux/ubuntu, check here for help.

LD_LIBRARY_PATH

This should contain the path in which the ignite driver is present. In my case, it is /usr/local/lib.

Make sure to export LD_LIBRARY_PATH (export LD_LIBRARY_PATH)

You might also want to add the location of libjvm.so. This is needed if you want to run the provided ignite examples. Refer here for help.

IGNITE_HOME

This should point to the ignite home directory

Starting ignite

To start ignite, go to the ignite home directory and run bin/ignite.sh script. You can provide a custom config file if you have one. There are several sample configurations in examples/config under the ignite home directory

PHP Integration

Enable php odbc support

You can check if your php installation has odbc support using the command php -i | grep PDO. If it contains the lines PDO drivers => odbc, etc, you have the odbc driver support

If the odbc is not listed in the PDO drivers, you either have to install the php-odbc package or enable the support in the php.ini file. In my case, I had to install the php5.6-odbc package.

PHP ODBC Connection

To connect to ignite from php, I have used the PDO class provided by php. Refer here for further info. Use the following code to connect,

new \PDO('odbc:Driver=Apache Ignite;ADDRESS=127.0.0.1:10800;Cache=default');

The input string is the odbc connection string used to connect using the odbc driver. Where Apache Ignite is the driver name defined in odbcinst.ini and default is the cache name you want to use and ADDRESS points to the server where ignite is running. Update them as necessary.

If the above string returns an error, check the error message. If the error says Failed to establish connection, make sure the ignite server/application is running. If it is Data source name not found, it means there is some problem with the driver/data source definition. Check your odbc.ini and odbcinst.ini files.

By default, ignite uses 10800 port for odbc connections

Having problems with connecting to ignite

Few things you can try

  • You can use the bin/ignitevisor.sh script to check the status and address of the nodes
  • You can try with different connection strings if that helps. You can do this from php interactive console for an easier approach.
  • Check if the ip and the port number are correct

Miscellaneous

As a cache

Ignite can also be used as a cache through the php memcache interface. Check here for help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment