Neo4j在通过PHP执行查询时速度非常慢,但在通过webadmin执行查询时非常快


Neo4j very slow when executing query through PHP but very fast through webadmin

我有以下问题。我写了一个查询:

  MATCH (n:RealNode {gid:'58687'})-[:CONTAINS*..15]-(z) RETURN DISTINCT ID(z), z.id,n.id as InternalID

我通过一个PHP脚本(通过发送POST请求)运行它。需要很长时间才能得到回应,有时neo4j会挂起。我在Neo4j网络管理员中尝试了同样的查询,并在中得到了响应

知道为什么在第一种情况下,响应需要这么长时间吗?

已编辑这是使用CURL:的请求

   $obj_id = $_POST['datastr'];
   $dataArr = array("query" => "MATCH (n {gid:'$obj_id'})-[:CONTAINS*..15]-(z) RETURN DISTINCT ID(z), z.id,n.id as InternalID");
  $data = json_encode($dataArr);
  $curl=curl_init();
  curl_setopt($curl,CURLOPT_HTTPHEADER,array('Accept: application/json; charset=UTF-8','Content-Type: application/json','Content-Length: ' . strlen($data),'X-Stream: true'));
  curl_setopt($curl, CURLOPT_URL, 'http://localhost:7474/db/data/cypher/');  
  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); //type of request   
  curl_setopt($curl, CURLOPT_POSTFIELDS,$data); // data to post
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // return response as string
  $response = curl_exec($curl);
  echo $response;
  curl_close($curl);

您正在使用遗留的Cypher端点。

我建议您使用Cypherhttp事务端点并使用查询参数。

http://neo4j.com/docs/stable/rest-api-transactional.html

此外,您还可以使用像NeoClient这样的php-neo4j驱动程序,它将消除curl的负担,并提供一个漂亮的响应格式化程序。