在 php Neo4j-php-client 中设置 Neo4j 连接超时

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

过去我们使用以下代码连接到neo:

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

setDefaultTimeout 已被弃用,默认的 curl 超时为 5 秒,这对于某些查询来说不够长。

我们可以改用螺栓,但螺栓连接中的 setDefaultTimeout 也可能会被弃用。

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

新的http连接超时设置方法如下:

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();

但是使用这种新方法我得到了一个 Unsupported Media Type 异常。
如果有人对此有所了解,请分享。

现在我们可以使用以下设置超时:

$neo_timeout = 999;
$neo_ip = "http://user:passwd@127.0.0.1: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();

已发布使用 php-http/curl-client 的修复程序
参见:https://github.com/graphaware/neo4j-php-client/pull/114