amphp / dns

Async DNS resolution for PHP based on Amp.

Home Page:https://amphp.org/dns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Too many time to resolve localhost domain

roquie opened this issue · comments

commented

Hi,

Versions:

  • amphp/dns v1.2.2
  • amphp/http-client v4.4.0
  • PHP 7.4.5 (cli) (built: Apr 23 2020 02:25:56) ( NTS )

Steps to reproduce:

  1. Run php web server php -S localhost:3001 -t / (or something else). Files are optional.
  2. Create file like index.php with following contents:
use Amp\Loop;
use Amp\File;

require __DIR__ . '/vendor/autoload.php';

Loop::run(function () {
    $client = \Amp\Http\Client\HttpClientBuilder::buildDefault();
    $request = new \Amp\Http\Client\Request('http://localhost:3001/', 'GET');
    $response = yield $client->request($request);
    echo yield $response->getBody()->buffer();
});
  1. Run curl time curl http://localhost:3001/
  2. Run time php index.php
roquie@roquies-MacBook-Pro:~/google_drive/projects/spacetab-io/github/gotenberg-sdk-php$ time php index.php 
"""
<!doctype html><html><head><title>404 Not Found</title><style>\n
body { background-color: #fcfcfc; color: #333333; margin: 0; padding:0; }\n
h1 { font-size: 1.5em; font-weight: normal; background-color: #9999cc; min-height:2em; line-height:2em; border-bottom: 1px inset black; margin: 0; }\n
h1, p { padding-left: 10px; }\n
code.url { background-color: #eeeeee; font-family:monospace; padding:0 2px;}\n
</style>\n
</head><body><h1>Not Found</h1><p>The requested resource <code class="url">/</code> was not found on this server.</p></body></html>
"""

real    0m10.096s
user    0m0.059s
sys     0m0.031s

DNS can't be resolve less than 10 seconds.

$ cat /etc/resolv.conf

nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 8.8.4.4
nameserver 1.0.0.1

If you use 0.0.0.0:3001 instead of localhost:3001 always works fine.

localhost should never be sent to any nameserver for resolution.

commented

That right. But I don't know why it resolving 10 seconds. Did you reproduce this?

No, I can't reproduce it: 0,09s user 0,03s system 91% cpu - 0,124 total

@roquie Could you check which IP Curl is using with curl -v http://localhost:3001/? Might be some IPv4 vs. IPv6 issue. And also check which IP the PHP web server is actually listening on?

commented

Oh, I forgot about this issue 😨

Curl output:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3001 (#0)
> GET / HTTP/1.1
> Host: localhost:3001
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< Host: localhost:3001
< Date: Tue, 28 Jul 2020 16:26:49 GMT
< Connection: close
< Content-Type: text/html; charset=UTF-8
< Content-Length: 533
< 
{ [533 bytes data]
100   533  100   533    0     0  88833      0 --:--:-- --:--:-- --:--:--  104k
* Closing connection 0

I updated composer packages to latest versions. I can still reproduce this.

If you try it with Amp, do [::1] and 127.0.0.1 work equally?

I'm closing this due to lack of feedback.