简体   繁体   中英

PHP Connection with neo4j “cURL error 7”

I followed steps in this related question but this error appeared to me, Can you help please?

HttpException in HttpRequestEventSubscriber.php line 74: Error on Connection "default" with message "cURL error 7: Failed to connect to localhost port 7474: Connection refused (see http://curl.haxx.se/libcurl/c/libcurl-errors.html )"

this is my .env code

`APP_ENV=local
APP_DEBUG=true
APP_KEY=ChTIcRHTSR35M6rP0jwmOmhMNLuFpMVe

NEO4J_HOST=localhost
NEO4J_PORT=7474
NEO4J_USER=neo4j
NEO4J_PASSWORD=admin
NEO4J_TIMEOUT=300

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
`

this is NeoClientServiceProvider code

    <?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Neoxygen\NeoClient\ClientBuilder;

class NeoClientServiceProvider extends ServiceProvider
{
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('neoclient', function ($app) {
            return ClientBuilder::create()
                ->addConnection('default', 'http', env('NEO4J_HOST'), intval(env('NEO4J_PORT')), true, env('NEO4J_USER'), env('NEO4J_PASSWORD'))
                ->setDefaultTimeout( intval(env('NEO4J_TIMEOUT')) )
                ->setAutoFormatResponse(true)
                ->build();
        });
    }
}

this is provider

 App\Providers\NeoClientServiceProvider::class,

aliases

'NeoClient' => App\NeoClient::class

this is NeoClient class code

 <?php namespace App;

use Illuminate\Support\Facades\Facade;

class NeoClient extends Facade
{

    protected static function getFacadeAccessor() { return 'neoclient'; }
}

my test controller

  <?php

namespace App\Http\Controllers;

use App\NeoClient;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class test extends Controller
{

    public function index()
    {

        $data = NeoClient::sendCypherQuery('CREATE (user:User {name:"Kenneth"}) RETURN user');

    }

}

when I made dump for this in function addConnection which is in ClientBuilder class

 public function addConnection($alias, $scheme, $host, $port, $authMode = false, $authUser = null, $authPassword = null)
    {
        $this->configuration['connections'][$alias] = array(
            'scheme' => $scheme,
            'host' => $host,
            'port' => $port,
            'auth' => $authMode,
            'user' => $authUser,
            'password' => $authPassword,
        );
  dd($this);
        return $this;
    }

这是转储的结果

Ok. I installed Homestead to reproduce your environment. As told in the comments this should have been a host issue. I managed to make your connection to neo4j working :

  1. ssh to homestead :

ssh vagrant@127.0.0.1 -p 2222

  1. display the gateway ip of the vagrant box :

vagrant@homestead:~$ ip route show default via 10.0.2.2 dev eth0 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.10

Here the host gateway is 10.0.2.2

  1. Use the gateway as neo4j host :

$ curl --user neo4j:admin "http://10.0.2.2:7474/db/data/" "extensions" : { }, "node" : "http://10.0.2.2:7474/db/data/node", "node_index" : "http://10.0.2.2:7474/db/data/index/node", "relationship_index" : "http://10.0.2.2:7474/db/data/index/relationship", "extensions_info" : "http://10.0.2.2:7474/db/data/ext", "relationship_types" : "http://10.0.2.2:7474/db/data/relationship/types", "batch" : "http://10.0.2.2:7474/db/data/batch", "cypher" : "http://10.0.2.2:7474/db/data/cypher", "indexes" : "http://10.0.2.2:7474/db/data/schema/index", "constraints" : "http://10.0.2.2:7474/db/data/schema/constraint", "transaction" : "http://10.0.2.2:7474/db/data/transaction", "node_labels" : "http://10.0.2.2:7474/db/data/labels", "neo4j_version" : "3.0.0-alpha.163"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM