gpt4 book ai didi

PHP 与 neo4j 的连接 "cURL error 7"

转载 作者:搜寻专家 更新时间:2023-10-31 21:05:56 26 4
gpt4 key购买 nike

我遵循了这个 related question 中的步骤但是这个错误出现在我身上,你能帮忙吗?

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)"

这是我的.env 代码

`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
`

这是 NeoClientServiceProvider 的代码

    <?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();
});
}
}

这是供应商<​​/p>

 App\Providers\NeoClientServiceProvider::class,

别名

'NeoClient' => App\NeoClient::class

这是 NeoClient 类代码

 <?php namespace App;

use Illuminate\Support\Facades\Facade;

class NeoClient extends Facade
{

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

我的测试 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');

}

}

当我在 ClientBuilder 类中的函数 addConnection 中为此进行转储时

 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;
}

this is the results of dump

最佳答案

好的。我安装了 Homestead 来重现您的环境。正如评论中所说,这应该是一个主机问题。我设法使您与 neo4j 的连接正常工作:

  1. ssh 到宅基地:


ssh 流浪者@127.0.0.1 -p 2222

  1. 显示 vagrant box 的网关 ip :


vagrant@homestead:~$ ip 路由显示
默认通过 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0 proto 内核范围链接 src 10.0.2.15
192.168.10.0/24 dev eth1 proto kernel scope link src 192.168.10.10

这里主机网关是10.0.2.2

  1. 将网关用作 neo4j 主机:


$ curl --user neo4j:admin "http://10.0.2.2:7474/db/data/"
“扩展”:{},
“节点”:“http://10.0.2.2:7474/db/data/node”,
“节点索引”:“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”,
“批处理”:“http://10.0.2.2:7474/db/data/batch”,
“密码”:“http://10.0.2.2:7474/db/data/cypher”,
“索引”:“http://10.0.2.2:7474/db/data/schema/index”,
“约束”:“http://10.0.2.2:7474/db/data/schema/constraint”,
“交易”:“http://10.0.2.2:7474/db/data/transaction”,
“节点标签”:“http://10.0.2.2:7474/db/data/labels”,
“neo4j_version”:“3.0.0-alpha.163”

关于PHP 与 neo4j 的连接 "cURL error 7",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32444507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com