neo4j graphaware php-client: Connection refused
I am running XAMPP locally on my MacBook. On the same computer, I run neo4j Enterprise. The database is version 3.5.6.
When I try to connect to the database through the php client, I get a warning and a fatal error:
Warning: stream_socket_client(): Failed to connect to tcp://localhost:7687 in /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-bolt/src/IO/StreamSocket.php (connection refused) 203
Fatal error: Uncaught GraphAware\Bolt\Exception\IOException: Error connecting to server (111): " in /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-bolt/src/IO/ Connection refused" StreamSocket.php: 207 Stack trace: #0 /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-bolt/src/IO/StreamSocket.php(245): GraphAware\Bolt\IO\ StreamSocket->connect() #1 /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-bolt/src/Driver.php(133): GraphAware\Bolt\IO\StreamSocket->reconnect() #2 /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-bolt/src/Driver.php(115): GraphAware\Bolt\Driver->handshake() #3 /opt/lampp/htdocs/avi-law_codetest /vendor/graphaware/neo4j-php-client/src/Connection/Connection.php(192): GraphAware\Bolt\Driver->session() #4 /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-php-client/src/Connection/Connection.php(109): GraphAware\Neo4j\Client\Connection\Connection->checkSession( ) #5 /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/neo4j-php-client/src/Client.php(220): in /opt/lampp/htdocs/avi-law_codetest/vendor/graphaware/ neo4j-bolt/src/IO/StreamSocket.php on line 207
The same story has changed https
(just with the other two ports in the error statement).
I have checked Username
(neo4j) and (Neo1234) to the database through the browser interface . Both are correct. I also tried replacing "localhost" with the IP address of the Apache server.password
require_once 'vendor/autoload.php';
use GraphAware\Neo4j\Client\ClientBuilder;
$client = ClientBuilder::create()
//->addConnection("default", "http://neo4j:Neo1234@localhost:7474")
->addConnection('bolt', 'bolt://neo4j:Neo1234@localhost:7687')
->build();
$query = 'MATCH (user:User {name:"john"})
CREATE (friend:User {name:"Judith"})
MERGE (user)-[r:FRIEND]->(friend)
RETURN user, friend, r';
$result = $client->sendCypherQuery($query)->getResult();
$john = $result->get('user');
$judith = $result->get('judith');
// What john has for relationships
print_r($john->getRelationships()); // returns relationships objects
If a var_dump() is performed on the $client variable, the result is as follows:
object(GraphAware\Neo4j\Client\Client)#23(2){[""connectionManager":protected] => object(GraphAware\Neo4j\Client\Connection\ConnectionManager)#2(2){[""connections": "GraphAware\Neo4j\Client\Connection\ConnectionManager": private] => array(1) { ["""] => object(GraphAware\Neo4j\Client\Connection\Connection) #4(5) { ["alias" : "GraphAware\Neo4j\Client\Connection\Connection":private] => string(4) "bolt" ["uri":"GraphAware\Neo4j\Client\Connection\Connection":private] => string(35 )" Bolt: //neo4j:Neo1234@localhost:7687" ["driver:"GraphAware\Neo4j\Client\Connection\Connection":private] => object(GraphAware\Bolt\Driver) #18(6) {[ "io":protected] => Object(GraphAware\Bolt\IO\StreamSocket) #21(9) { ["protocol":protected] => string(3) "tcp" ["host":protected] => string (9) "localhost" ["port":protected] =>int(7687)["context":protected] => resource(64) of type (stream context)["keepAlive":protected] => bool(false)["eventDispatcher":protected] => object(Symfony\ Component\EventDispatcher\EventDispatcher) #20(3) { ["listeners":"Symfony\Component\EventDispatcher\EventDispatcher":private] => array(0){}["sorted":"Symfony\Component\Event\Dispatcher \EventDispatcher":private] => array(0){ }[""optimized":"Symfony\Component\EventDispatcher\EventDispatcher":private] => array(0){}}["timeout":protected] => int(5)["sock":"GraphAware\Bolt\IO\StreamSocket":private] =>NULL["configuration":"GraphAware\Bolt\IO\StreamSocket":private] =>Object(GraphAware\Bolt\Configuration ) #19(7) { ["credentials": protected] => array(2) { [0] => string(5) "neo4j"[1] => string(7) "Neo1234" } [" username":protected] => string(5) "neo4j" ["password":protected] =>String(7) "Neo1234"["bindtoInterface":protected] => NULL["timeout":protected] => NULL["tlsMode":protected] => NULL["data":"GraphAware\Common \Connection\BaseConfiguration": private] => array(6) { ["user"] => string(4) "null"["password"] => string(7) "Neo1234"["bind_to_interface"] => string(4) "null" ["timeout"] => int(5) ["credentials"] => array(2) { [0] => string(5) "neo4j" [1] => string (7) "Neo1234" } ["username"] => String (5) "neo4j" } }} [""dispatcher":protected] => Object(Symfony\Component\EventDispatcher\EventDispatcher) #20 (3) {[""listener":"Symfony\Component\EventDispatcher\EventDispatcher":private] => array(0){}["sorted":"Symfony\Component\EventDispatcher\EventDispatcher":private]= > array(0){}[""Optimized":"Symfony\Component\EventDispatcher\EventDispatcher":private] => array(0){}}["sessionRegistry":protected] =>object(GraphAware \ Bolt \ Protocol \ SessionRegistry)#22(3){[“” io“:protected] => object(GraphAware \ Bolt \ IO \ StreamSocket)#21( 9){[“ protocol”:protected] => string(3)“tcp“ [” host“:protected] =>字符串(9)” localhost“ [” port“:protected] => int(7687)[” context“:protected] =>资源(64)类型(stream-context )[“ keepAlive”:protected] => bool(false)[“ eventDispatcher”:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#20(3){[“” listeners“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” optimized“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){}} [” timeout“:protected] =>int(5)["sock":"GraphAware\Bolt\IO\StreamSocket":private] => NULL["Configuration":"GraphAware\Bolt\IO\StreamSocket":private] => object(GraphAware\Bolt\ Configuration) #19(7) { [""credentials": protected] => array(2) { [0] => string(5) "neo4j"[1] => string(7) "Neo1234"} ["username": protected] => string(5) "neo4j" ["password": protected] => string(7) "Neo1234" ["bindtoInterface": protected] => NULL[" timeout ":protected] => NULL["tlsMode":protected] => NULL["data":"GraphAware\Common\Connection\BaseConfiguration":private] => array(6) { ["user"] => string( 4) "null"["password"] => string(7) "Neo1234"["bind_to_interface"] => string(4) "null"["timeout"] => int(5)["credentials"] = >array(2){[0]=>string(5)"neo4j"[1]=>string(7)"Neo1234"}["username"]=>string(5)"neo4j"}}}[" dispatcher": protected] =>object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#20(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ Event \ Dispatcher \ EventDispatcher “:private] => array(0){} [”优化“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){}} [”会话“:受保护] => array(1 ){[1] =>字符串(35)“ GraphAware \ Bolt \ Protocol \ V1 \ Session”}} [“ versionAgreed”:protected] => bool(false)[“ session”:protected] => NULL [“凭据“:protected] => array(2){[0] =>string(5)“ neo4j” [1] => string(7)“ Neo1234”}} [“ config”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection”:private] => object(GraphAware \ Neo4j \ Client \ HttpDriver \ Configuration)#17(3){[“” timeout“:protected] => NULL [” curlInterface“:protected] =>NULL [” data“:” GraphAware \ Common \ Connection \ BaseConfiguration“:private] =>数组(3){[“ http_client”] =>对象(Http \ Adapter \ Guzzle6 \ Client)#5(1){[“ client”:“ Http \ Adapter \ Guzzle6 \ Client”:private] =>对象(GuzzleHttp \客户端)#15(1){[“” config“:” GuzzleHttp \ Client“:private] => array(7){[”“ handler”] => object(GuzzleHttp \ HandlerStack)#6(3){[“” handler “:” GuzzleHttp \ HandlerStack“:private] => object(Closure)#13(2){[”static“] => array(2){[”“ default”] => object(Closure)#11(2){[“” static“] => array(2){[”“ default”] => object(GuzzleHttp \ Handler \ CurlMultiHandler)#7(5){[“” factory:“ GuzzleHttp \ Handler \ CurlMultiHandler”:private] => object(GuzzleHttp \ Handler \ CurlFactory)#8(2){[“” handles“:” GuzzleHttp \ Handler \ CurlFactory“:private] =>array(0){} [” maxHandles“:” GuzzleHttp \ Handler \ CurlFactory“:private] => int(50)} [” selectTimeout“:” GuzzleHttp \ Handler \ CurlMultiHandler“:private ] => int(1)[“ active”:“ GuzzleHttp \ Handler \ CurlMultiHandler”:private] => NULL [“ handles”:“ GuzzleHttp \ Handler \ CurlMultiHandler”:private] => array(0){} [“ delays“:” GuzzleHttp \ Handler \ CurlMultiHandler“:private] => array(0){}} [“ sync”] =>对象(GuzzleHttp \ Handler \ CurlHandler)#9(1){[“ factory:” GuzzleHttp \ Handler \ CurlHandler“:private] =>对象(GuzzleHttp \ Handler \ CurlFactory)#10(2){[“ handles”:“ GuzzleHttp \ Handler \ CurlFactory”:private] => array(0){} [“ maxHandles”:“ GuzzleHttp \ Handler \ CurlFactory”:private ] => int(3)}}} [“参数”] => array(2){[“ $ request”] => string(10)“” [“ $$ options”] => string(10)“” }} [“ streaming”] =>object(GuzzleHttp \ Handler \ StreamHandler)#12(1){[“ lastHeaders”:“ GuzzleHttp \ Handler \ StreamHandler”:private] => array(0){}}}} [“参数“] => array(2){[”“ $ request”] => string(10)“” [“ $ options”] =>string(10)“”}} [“ stack”:“ GuzzleHttp \ HandlerStack”:private] => array(1){[0] => array(2){[0] => object(Closure)#14( 1){[“ parameter”] => array(1){[“” handler“] => string(10)”“}} [1] => string(12)” prepare_body“}} [” cached“: “ GuzzleHttp \ HandlerStack”:private] => NULL} [“ allow_redirects”] => array(5){[“” max“] => int(5)[” protocols“] => array(2){[0] =>字符串(4)“ http” [1] =>字符串(5)“ https”} [“严格”] => bool(false)[“ referer”] => bool(false)[“ track_redirects”] => > bool(false)} [“ http_errors”] => bool(true)[“ decode_content”] => bool(true)[“ verify”] => bool(true)[“ cookies”] =>bool(false)[“ headers”] => array(1){[“ User-Agent”] => string(39)“ GuzzleHttp / 6.3.3 curl / 7.53.1 PHP / 7.3.10”}}}} [“ request_factory”] =>对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}array(0){}}}array(0){}}}array(1){[“ User-Agent”] => string(39)“ GuzzleHttp / 6.3.3 curl / 7.53.1 PHP / 7.3.10”}}}} [“ request_factory”] =>对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}array(1){[“ User-Agent”] => string(39)“ GuzzleHttp / 6.3.3 curl / 7.53.1 PHP / 7.3.10”}}}} [“ request_factory”] =>对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}3 curl / 7.53.1 PHP / 7.3.10”}}}} [“ request_factory”] =>对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}3 curl / 7.53.1 PHP / 7.3.10”}}}} [“ request_factory”] =>对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}对象(Http \ Message \ MessageFactory \ GuzzleMessageFactory)#16(0){} [“ timeout”] => int(5)}} [“ session”:“ GraphAware \ Neo4j \ Client \ Connection \ Connection“:private] => NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}NULL}} [” master“:” GraphAware \ Neo4j \ Client \ Connection \ ConnectionManager“:private] => NULL} [” eventDispatcher“:protected] => object(Symfony \ Component \ EventDispatcher \ EventDispatcher)#24(3){[“ listeners:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private] => array(0){} [” sorted“:” Symfony \ Component \ EventDispatcher \ EventDispatcher“:private ] => array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}array(0){} [“ optimized”:“ Symfony \ Component \ EventDispatcher \ EventDispatcher”:private] => array(0){}}}
The settings in neo4j.conf are in their default state.
The problem is solved. This is the (bad) relationship between XAMPP Apache and the onboard Mac OS Apache. They interfere somehow when you try to access " http://localhost " . I have stopped XAMPP Apache, followed the steps given here and the problem is solved.