当请求另一个资源时,狂饮打开localhost:8099:GuzzleHttp\异常\连接异常:cURL错误7:无法连接到本地主机:8099

kq0g1dla  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(479)

我在GuzzleHttp客户端使用laravel(8.78.1)。我调用了一些域。在我的代码中没有使用http://localhost:8099,但是当代码调用时,我在生产日志中看到了错误消息。我在Ubuntu上设置了这个项目,使用了docker,php:8.1-fpm,certbot/certbot:v1.22.0。它作为一个docker容器运行。我试图在没有docker的情况下安装它,但是它以同样的方式工作。尽管出现了这个错误消息,实际的请求仍然成功执行。代码完成,没有异常。
在我的本地机器上没有这样的问题。
local.ERROR:GuzzleHttp\异常\连接异常:cURL错误7:无法连接到本地主机端口8099:连接被拒绝(请参见https://curl.haxx.se/libcurl/c/libcurl-errors.html),因为连接失败的原因是:
编码:

public function list(): array
    {

        // ...

        $url = $this->getRequestUrl("customer/list");
        $client = $this->getClient();
        $response = $client->request('GET', $url);
        $responseArray = json_decode($response->getBody(), true);
        // ...

    }

    protected function getRequestUrl(string $endpoint, string $params = ""): string
    {
        return "{$this->getBaseUrl()}$endpoint";
    }

    protected function getClient(): Client
    {
        return new Client([
            'base_uri' => $this->getBaseUrl(),
            'headers' => [
                'Accept' => 'application/json; charset=utf-8'
            ]
        ]);
    }

    protected function getBaseUrl(): string
    {
        return "https://example.com/api/";
    }

堆栈追踪:

[2022-02-15 19:41:58] local.ERROR: GuzzleHttp\Exception\ConnectException: cURL error 7: Failed to connect to localhost port 8099: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8099 in /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210
Stack trace:
#0 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(28): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php(48): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#5 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(64): GuzzleHttp\Handler\Proxy::GuzzleHttp\Handler\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#6 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Middleware.php(31): GuzzleHttp\PrepareBodyMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#7 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php(71): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#8 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Middleware.php(63): GuzzleHttp\RedirectMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#9 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/HandlerStack.php(75): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Request), Array)
#10 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Client.php(331): GuzzleHttp\HandlerStack->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#11 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Client.php(168): GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#12 /var/www/html/laravel/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Client->requestAsync('POST', Object(GuzzleHttp\Psr7\Uri), Array)
#13 /var/www/html/laravel/vendor/jkocik/laravel-profiler/src/Processors/BroadcastingProcessor.php(57): GuzzleHttp\Client->request('POST', 'http://localhos...', Array)
#14 /var/www/html/laravel/vendor/jkocik/laravel-profiler/src/Processors/BroadcastingProcessor.php(42): JKocik\Laravel\Profiler\Processors\BroadcastingProcessor->broadcast(Object(JKocik\Laravel\Profiler\LaravelDataTracker), 'http://localhos...')
#15 /var/www/html/laravel/vendor/jkocik/laravel-profiler/src/LaravelDataProcessor.php(58): JKocik\Laravel\Profiler\Processors\BroadcastingProcessor->process(Object(JKocik\Laravel\Profiler\LaravelDataTracker))
#16 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Collections/Traits/EnumeratesValues.php(242): JKocik\Laravel\Profiler\LaravelDataProcessor->JKocik\Laravel\Profiler\{closure}('JKocik\\Laravel\\...', 0)
#17 /var/www/html/laravel/vendor/jkocik/laravel-profiler/src/LaravelDataProcessor.php(62): Illuminate\Support\Collection->each(Object(Closure))
#18 /var/www/html/laravel/vendor/jkocik/laravel-profiler/src/LaravelProfiler.php(96): JKocik\Laravel\Profiler\LaravelDataProcessor->process(Object(JKocik\Laravel\Profiler\LaravelDataTracker))
#19 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): JKocik\Laravel\Profiler\LaravelProfiler->JKocik\Laravel\Profiler\{closure}()
#20 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#21 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(81): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#22 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure), Object(Closure))
#23 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(653): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Object(Closure), Array, NULL)
#24 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1158): Illuminate\Container\Container->call(Object(Closure))
#25 /var/www/html/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(182): Illuminate\Foundation\Application->terminate()
#26 /var/www/html/laravel/public/index.php(55): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpFoundation\Response))
#27 {main}
ljsrvy3e

ljsrvy3e1#

原因是jkocik/laravel-profiler提出了一个请求。简单地从包中删除它就解决了问题。

相关问题