Albert S
Albert S

Reputation: 2602

Setting a timeout on Neo4j connection in php Neo4j-php-client

In the past we used the following code to connect to neo:

use GraphAware\Neo4j\Client\ClientBuilder;
 $neo4j  = ClientBuilder::create()
            -> addConnection('default', $neo_ip)
            -> setDefaultTimeout($neo_timeout)
            -> build();

setDefaultTimeout has been deprecated, default curl timeout is 5 seconds which is not long enough for some queries.

We can use bolt instead, but setDefaultTimeout in the bolt connection may become deprecated as well.

use GraphAware\Neo4j\Client\ClientBuilder;
$neo4j  = ClientBuilder::create()
           -> addConnection('bolt',    $neo_bolt_ip)
            -> setDefaultTimeout($neo_timeout)
            -> build();

The new way of setting timeout on an http connection is as follows:

use GraphAware\Neo4j\Client\ClientBuilder;
use Http\Client\Curl\Client;
$options = [
        CURLOPT_CONNECTTIMEOUT => 99, // The number of seconds to wait while trying to connect.
        CURLOPT_SSL_VERIFYPEER => false   // Stop cURL from verifying the peer's certificate
    ];
    $httpClient = new Client(null, null, $options);
    $config = \GraphAware\Neo4j\Client\HttpDriver\Configuration::create($httpClient);

    $neo4j  = ClientBuilder::create()
            -> addConnection('default', $neo_ip, $config)
            -> build();

However using this new way i am getting an Unsupported Media Type exception.
If anyone has some insight into this, please share.

Upvotes: 0

Views: 343

Answers (1)

Albert S
Albert S

Reputation: 2602

for now we can use the following to set timeout:

$neo_timeout = 999;
$neo_ip = "http://user:[email protected]:7474";
use GraphAware\Neo4j\Client\ClientBuilder;
$httpClient = \Http\Adapter\Guzzle6\Client::createWithConfig(['timeout'=>$neo_timeout]);
$config = \GraphAware\Neo4j\Client\HttpDriver\Configuration::create($httpClient);

$neo4j  = ClientBuilder::create()
        -> addConnection('default', $neo_ip, $config)
        -> build();

the fix for using php-http/curl-client has been issued
see: https://github.com/graphaware/neo4j-php-client/pull/114

Upvotes: 0

Related Questions