Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
10-06-2018 04:15 AM
Hello all,
i think i have a connection problem from my local Apache-Server to my local Neo4j-Server.
The connection always takes about a second. Can this be a configuration problem? I use the default configuration from Neo4j in version 3.4.1 and PHP 7.1. How long does it usually take to create the session?
Here is my code snippet.
require_once '../vendor/autoload.php';
use GraphAware\Bolt\GraphDatabase;
$config = GraphAware\Bolt\Configuration::create()
->withCredentials('neo4j', 'test');
$driver = GraphDatabase::driver("bolt://localhost", $config);
$session = $driver->session();
//$session->run('MATCH (n:Person) RETURN n LIMIT 25');
$session->close();
10-08-2018 05:48 AM
i've used other Frameworks to connect, the problem is the same. With the client from "Neoxygen" it only need 450ms for the first Query. Thats better, but way to long for productiv use. The second Query is no more measurable, because its to fast. The Problem is, that my application asks each single request to an php-backend, so the backend must etablish a new connect for every request.
10-19-2018 03:16 PM
With the following script, I return 1000 nodes in 24ms, on a local database. I would check that the latency between your app and the db isn't too high, or check also the dns resolution.
<?php
require_once __DIR__ .'/vendor/autoload.php';
$client = \GraphAware\Neo4j\Client\ClientBuilder::create()
->addConnection('default', 'bolt://neo4j:pass@localhost:7687')
->build();
$t = microtime(true);
$query = 'MATCH (n:Keyword) RETURN n.value LIMIT 10000';
$result = $client->run($query);
foreach ($result->records() as $record) {
//
}
echo sprintf('Retrieved %d nodes in %f \n', $result->size(), (microtime(true) - $t));
ikwattro@mbp666-019 ~/d/phptest> php test.php
Retrieved 1001 nodes in 0.024429 \n⏎
10-21-2018 02:15 AM
If I use "127.0.0.1" instead of "localhost" I will get similar times. Compared to a Mysql connection the performance of Neo4j is still too bad.
#Test with Neo4j
$t = microtime(true);
require_once __DIR__ .'/vendor/autoload.php';
$client = \GraphAware\Neo4j\Client\ClientBuilder::create()
->addConnection('default', 'bolt://neo4j:test@127.0.0.1:7687')
->build();
$query = 'MATCH (n:Tool) RETURN n LIMIT 10000';
$result = $client->run($query);
echo sprintf('Retrieved %d nodes in %f \n', $result->size(), (microtime(true) - $t));
C:\xampp\php
λ php d:\htdocs\neo4j_test.php
Retrieved 5 nodes in 0.038917 \n
C:\xampp\php
λ php d:\htdocs\neo4j_test.php
Retrieved 5 nodes in 0.041869 \n
#Test with Mysql
<?php
$t = microtime(true);
$link = mysqli_connect("127.0.0.1", "root", "", "testdb");
$sql_statement = "SELECT * FROM tools";
$result= $link->query($sql_statement);
$arr = array();
while ($row = $result->fetch_row()) {
$arr[] = $row;
}
$link->close();
echo sprintf('Retrieved %d rows in %f \n', count($arr), (microtime(true) - $t));
C:\xampp\php
λ php d:\htdocs\mysql_test.php
Retrieved 5 rows in 0.001356 \n
C:\xampp\php
λ php d:\htdocs\mysql_test.php
Retrieved 5 rows in 0.000970 \n
09-01-2021 12:11 AM
Hello,
I have the same problem, Do you solved it or still each request need to establish a new connection?
09-01-2021 01:27 AM
Hi, you should not use the GraphAware driver anymore, since it hasn't been maintained for a number of years.
Have you tried GitHub - neo4j-php/neo4j-php-client: Php client for neo4j database?
09-01-2021 03:09 AM
Thanks for your reply,
I already use this new driver and this my code
$auth = Authenticate::basic(env('DB_USERNAME_NEO4J'), env('DB_PASSWORD_NEO4J'));
$client = ClientBuilder::create()
->withDriver('bolt', env('DB_BOLT_NEO4J'), $auth)
->withDefaultDriver('bolt')
->build();
return $client->runStatement($statement);
But the problem is when run any request the runStatement() takes a long time
All the sessions of the conference are now available online