PHPackages                             brightzone/gremlin-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. brightzone/gremlin-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

brightzone/gremlin-php
======================

gremlin-server client for php

v3.1.1(7y ago)74194.5k—8.3%18[2 PRs](https://github.com/PommeVerte/gremlin-php/pulls)4Apache 2PHPPHP &gt;=5.5

Since Mar 27Pushed 3y ago6 watchersCompare

[ Source](https://github.com/PommeVerte/gremlin-php)[ Packagist](https://packagist.org/packages/brightzone/gremlin-php)[ RSS](/packages/brightzone-gremlin-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (26)Used By (4)

This is a Gremlin server client for PHP. It allows you to run gremlin queries against graph databases (including Neo4j, Titan, etc.). You can find a beginner tutorial by reading the [Get up and running with Tinkerpop 3 and PHP](https://dylanmillikin.wordpress.com/2015/07/20/get-up-and-running-with-tinkerpop-3-and-php/) article.

This driver currently supports TP3+.

For a TP2 compatible php driver please check [rexpro-php](https://github.com/PommeVerte/rexpro-php)

[![Build Status](https://camo.githubusercontent.com/fd1989ca4d4989268d2b83f3f45b37126b3820ca51ac57d99e003782de2e0c1b/68747470733a2f2f7472617669732d63692e636f6d2f506f6d6d6556657274652f6772656d6c696e2d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/PommeVerte/gremlin-php) [![Latest Stable Version](https://camo.githubusercontent.com/fde6f32b6c8418bb2638b3afdc14c0e53aa458f4dd5ae4df740fbed4c0f7d026/68747470733a2f2f706f7365722e707567782e6f72672f6272696768747a6f6e652f6772656d6c696e2d7068702f762f737461626c65)](https://packagist.org/packages/brightzone/gremlin-php) [![Coverage Status](https://camo.githubusercontent.com/e769c2ff5ca3eb6f242ae2ea7a50f4d70f077f5926d7879efecbed9515777b5f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f506f6d6d6556657274652f6772656d6c696e2d7068702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/PommeVerte/gremlin-php?branch=master) [![Total Downloads](https://camo.githubusercontent.com/6449271b242f612ff21e37850959df4c4d02eed0ef9f3aae895dae058437733e/68747470733a2f2f706f7365722e707567782e6f72672f6272696768747a6f6e652f6772656d6c696e2d7068702f646f776e6c6f616473)](https://packagist.org/packages/brightzone/gremlin-php) [![License](https://camo.githubusercontent.com/6a900ece973bc13bb775a907643132864db79812935eb29b621947adcbefe355/68747470733a2f2f706f7365722e707567782e6f72672f6272696768747a6f6e652f6772656d6c696e2d7068702f6c6963656e7365)](https://packagist.org/packages/brightzone/gremlin-php)

[![Join the chat at https://gitter.im/PommeVerte/gremlin-php](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/PommeVerte/gremlin-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Installation
============

[](#installation)

### PHP Gremlin-Server Client

[](#php-gremlin-server-client)

Preferred method is through composer.

Either run :

```
php composer.phar require brightzone/gremlin-php "3.*"
```

Or add:

```
"brightzone/gremlin-php": "3.*"
```

to the `require` section of your `composer.json` file

### Tinkerpop 3.3.x server Configuration

[](#tinkerpop-33x-server-configuration)

This driver now supports `GraphSON 3.0` with a basic beta serializer. You can use this serializer by doing :

```
  $db = new Connection();
  $db->message->registerSerializer('\Brightzone\GremlinDriver\Serializers\Gson3', TRUE);
```

If you wish to continue using the stable `GraphSON 1.0` serializer it is necessary to configure the server to use `GraphSON 1.0`. To do this, make sure to replace the `# application/json` serializer in your `gremlin-server.yaml` configuration file with the following:

```
- { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { ioRegistries: [org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerIoRegistryV1d0]  }}        # application/json
```

Upgrading
=========

[](#upgrading)

BC breaking changes are introduced between major version changes. So if you're upgrading to `2.0.0` from `1.0`. Please read the [CHANGELOG](CHANGELOG.md)

Usage
=====

[](#usage)

The Connection class exists within the `GremlinDriver` namespace.

```
require_once('vendor/autoload.php');
use \Brightzone\GremlinDriver\Connection;

$db = new Connection;
```

Features
========

[](#features)

You can find more information by reading the [API](http://pommeverte.github.io/gremlin-php/).

### Basic connection

[](#basic-connection)

A basic connection can be created by creating a new `Connection` as follows.

```
$db = new Connection([
    'host' => 'localhost',
    'graph' => 'graph'
]);
//you can set $db->timeout = 0.5; if you wish
$db->open();

$result = $db->send('g.V(2)');
//do something with result
$db->close();
```

Note that "graph" is the name of the graph configured in gremlin-server (not the reference to the traversal which is `g = graph.traversal()`)

It is also possible to specify authentication credentials as follows:

```
$db = new Connection([
    'host' => 'localhost',
    'graph' => 'graph',
    'username' => 'pomme',
    'password' => 'hardToCrack'
]);
//you can set $db->timeout = 0.5; if you wish
$db->open();
$db->send('g.V(2)');
//do something with result
$db->close();
```

Check the SSL section for an example using the configuration files provided by TP.

You can find all the options available to the `Connection` class [here](http://pommeverte.github.io/gremlin-php/brightzone-gremlindriver-connection.html).

Bindings
--------

[](#bindings)

Bindings are important for several reasons. They protect from code injections, but they also prevent the server from having to compile scripts on every run.

The following example illustrates both of these points:

```
$unsafeUserValue = 2; //This could be anything submitted via form.
$db = new Connection([
    'host' => 'localhost',
    'port' => 8182,
    'graph' => 'graph',
]);
$db->open();

$db->message->bindValue('CUSTO_BINDING', $unsafeUserValue); // protects from injections
$result1 = $db->send('g.V(CUSTO_BINDING)'); // The server compiles this script and adds it to cache

$db->message->bindValue('CUSTO_BINDING', 5);
$result2 = $db->send('g.V(CUSTO_BINDING)'); // The server already has this script so gets it from cache without compiling it, but runs it with 5 instead of $unsafeUserValue
$result3 = $db->send('g.V(5)'); // The script is different so the server compiles this script and adds it to cache

//do something with result
$db->close();
```

As you can see from the example above, not using bindings can be costly as the server needs to compile every new script.

Sessions
--------

[](#sessions)

Sessions allow you to maintain variables and bindings accross multiple requests.

```
$db = new Connection([
    'host' => 'localhost',
    'port' => 8182,
]);
$db->open();
$db->send('cal = 5+5', 'session'); // first query sets the `cal` variable
$result = $db->send('cal', 'session'); // result = [10]
//do something with result
$db->close();
```

Transactions
------------

[](#transactions)

Transactions will allow you to revert or confirm a set of changes made accross multiple requests.

```
$db = new Connection([
    'host' => 'localhost',
    'port' => 8182,
    'graph' => 'graphT',
]);
$db->open();

$db->transactionStart();

$db->send('t.addV().property("name","michael")');
$db->send('t.addV().property("name","john")');

$db->transactionStop(FALSE); //rollback changes. Set to TRUE to commit.
$db->close();
```

Note that "graphT" above refers to a graph that supports transactions. And that transactions start a session automatically. You can check which features are supported by your graph with `graph.features()`.

It is also possible to express transactions with a lambda notation:

```
$db = new Connection([
    'host' => 'localhost',
    'port' => 8182,
    'graph' => 'graphT',
]);
$db->open();

$db->transaction(function($db){
    $db->send('t.addV().property("name","michael")');
    $db->send('t.addV().property("name","john")');
}, [$db]);

$db->close();
```

This will commit these changes or return an `Exception` if an error occured (and automatically rollback changes). The advantage of using this syntax is that it allows you to handle fail-retry scenarios.

It is sometimes important to implement a fail-retry strategy for your transactional queries. One such example is in the event of concurrent writes to the same elements, the databases (such as titan) will throw an error when elements are locked. When this happens you will most likely want the driver to retry the query a few times until the element is unlocked and the write can proceed. For such instances you can do:

```
$db = new Connection([
    'host' => 'localhost',
    'port' => 8182,
    'graph' => 'graphT',
    'retryAttempts' => 10
]);
$db->open();

$db->transaction(function($db){
    $db->send('t.addV().property("name","michael")');
    $db->send('t.addV().property("name","john")');
}, [$db]);

$db->close();
```

This will attempt to run the query 10 times before fully failing. It is worth noting that `retryAttempts` also works with -out of session- queries:

```
$db->send('gremlin.code.here'); // will retry multiple times if 'retryAttempts' is set
```

Advanced features
=================

[](#advanced-features)

Message objects
---------------

[](#message-objects)

Sometimes you may need to have greater control over individual requests. The reasons for this can range from using custom serializers, different query languages (`gremlin-python`, `gremlin-scala`, `java`), to specifying a request timeout limit or a local alias. For these cases you can construct a custom `Message` object as follows:

```
$message = new Message;
$message->gremlin = 'custom.V()'; // note that custom refers to the graph traversal set on the server as g (see alias bellow)
$message->op = 'eval'; // operation we want to run
$message->processor = ''; // the opProcessor the server should use
$message->setArguments([
                'language' => 'gremlin-groovy',
                'aliases' => ['custom' => 'g'],
                // ... etc
]);
$message->registerSerializer('\Brightzone\GremlinDriver\Serializers\Json');

$db = new Connection();
$db->open();
$db->send($message);
//do something with result
$db->close();
```

Of course you can affect the current db message in the same manner through `$db->message`.

For a full list of arguments and values available please refer to the [TinkerPop documentation for drivers](http://tinkerpop.apache.org/docs/current/dev/provider/#_opprocessors_arguments).

SSL
---

[](#ssl)

When security is important you will want to use the SSL features available. you can do so as follows:

```
$db = new Connection([
    'host' => 'localhost',
    'graph' => 'graph',
    'ssl' => TRUE
]);
//you can set $db->timeout = 0.5; if you wish
$db->open();
$db->send('g.V(2)');
//do something with result
$db->close();
```

*Note that with php 5.6+ you will need to provide certificate information in the same manner you would to a `stream_context_create()`. In which case your `Connection()` call could look something like the following (replace with your own certificates and/or bundles):*

```
$db = new Connection([
    'host' => 'localhost',
    'graph' => 'graph',
    'ssl' => [
        "ssl"=> [
            "cafile" => "/path/to/bundle/ca-bundle.crt",
            "verify_peer"=> true,
            "verify_peer_name"=> true,
        ]
    ]
]);
```

If you're using the bundled `gremlin-server-secure.yaml` file, you can use [this configuration](https://github.com/PommeVerte/gremlin-php/blob/master/tests/AuthTest.php#L23-L35) to connect to it. For dev and testing purposes you can use [this configuration](https://github.com/PommeVerte/gremlin-php/blob/master/tests/AuthTest.php#L29-L34)

Serializers
-----------

[](#serializers)

Serializers can be changed on the gremlin-server level. This allows users to set their own serializing rules. This library comes by default with a Json serializer. Any other serializer that implements `SerializerInterface` can be added dynamically with:

```
$db = new Connection;
$serializer = $db->message->getSerializer() ; // returns an instance of the default JSON serializer
echo $serializer->getName(); // JSON
echo $serializer->getMimeType(); // application/json

$db->message->registerSerializer('namespace\to\my\CustomSerializer', TRUE); // sets this as default
$serializer = $db->message->getSerializer(); // returns an instance of the CustomSerializer serializer (default)
$serializer = $db->message->getSerializer('application/json'); // returns an instance of the JSON serializer
```

You can add many serializers in this fashion. When gremlin-server responds to your requests, gremlin-php will be capable of using the appropriate one to unserialize the message.

API
===

[](#api)

You can find the full api [here](http://pommeverte.github.io/gremlin-php/).

Unit testing
============

[](#unit-testing)

Neo4J is required for the full test suit. It is not bundled with gremlin-server by default so you will need to manually install it with:

```
bin/gremlin-server.sh -i org.apache.tinkerpop neo4j-gremlin 3.2.8
```

(replace the version number by the one that corresponds to your gremlin-server version)

Copy the following files :

```
cp /build/server/gremlin-server-php.yaml /conf/
cp /build/server/neo4j-empty.properties /conf/
cp /build/server/gremlin-php-script.groovy /scripts/
```

You will then need to run gremlin-server in the following manner :

```
bin/gremlin-server.sh conf/gremlin-server-php.yaml
```

Then run the unit test via:

```
# make sure test dependecies are installed
composer install # PHP >=5.6
composer update # PHP 5.5

# Run the tests
phpunit -c build/phpunit.xml
```

### Browser /tests/webtest.php file

[](#browser-testswebtestphp-file)

If your gremlin-php folder is on the web path. You can also load `tests/webtest.php` instead of using the command line to run PHPUNIT tests.

This is useful in some wamp or limited access command line situations.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity49

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 98.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Recently: every ~227 days

Total

19

Last Release

2674d ago

Major Versions

v0.6 → v1.02015-07-19

v1.0 → v2.0.02015-10-01

v2.2.3 → v3.0.02016-07-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/1003540c62e92cfee08bbdbd7d338a4a625f2fd9dffa90bf15963c42fc74ea78?d=identicon)[PommeVerte](/maintainers/PommeVerte)

---

Top Contributors

[![dmill-bz](https://avatars.githubusercontent.com/u/1415875?v=4)](https://github.com/dmill-bz "dmill-bz (266 commits)")[![koga187](https://avatars.githubusercontent.com/u/2582694?v=4)](https://github.com/koga187 "koga187 (2 commits)")[![amore012](https://avatars.githubusercontent.com/u/11745633?v=4)](https://github.com/amore012 "amore012 (1 commits)")[![gitter-badger](https://avatars.githubusercontent.com/u/8518239?v=4)](https://github.com/gitter-badger "gitter-badger (1 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

drivergremlinrexpro-phprexprogremlin-server

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brightzone-gremlin-php/health.svg)

```
[![Health](https://phpackages.com/badges/brightzone-gremlin-php/health.svg)](https://phpackages.com/packages/brightzone-gremlin-php)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
