0

过去我们使用以下代码连接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例外。
如果有人对此有所了解,请分享。

4

1 回答 1

0

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

$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

于 2017-06-29T17:44:39.613 回答