reactphp-legacy / whois

Whois client based on ReactPHP.
MIT License
71 stars 15 forks source link

Lost Results #2

Closed umpirsky closed 12 years ago

umpirsky commented 12 years ago

In this example I prepared 10 whois queries:

<?php

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

$loop = React\EventLoop\Factory::create();
$factory = new React\Dns\Resolver\Factory();
$resolver = $factory->create('8.8.8.8', $loop);

$connFactory = function ($ip) use ($loop) {
    $fd = stream_socket_client("tcp://$ip:43");
    return new React\Socket\Connection($fd, $loop);
};

$domainTpl = 'igor%s.io';

$client = new React\Whois\Client($resolver, $connFactory);
for ($i = 1; $i <= 10; $i++) {
    $domain = sprintf($domainTpl, $i);
    echo "Getting whois for $domain...\n";
    $client->query($domain, function ($result) {
        echo $result;
    });
}

$loop->run();

But in the output I found only 5 results:

Getting whois for igor1.io...
Getting whois for igor2.io...
Getting whois for igor3.io...
Getting whois for igor4.io...
Getting whois for igor5.io...
Getting whois for igor6.io...
Getting whois for igor7.io...
Getting whois for igor8.io...
Getting whois for igor9.io...
Getting whois for igor10.io...
Domain "IGOR1.IO" - Available
To purchase please go to http://www.nic.io/
Domain "IGOR9.IO" - Available
To purchase please go to http://www.nic.io/
Domain "IGOR3.IO" - Available
To purchase please go to http://www.nic.io/
Domain "IGOR6.IO" - Available
To purchase please go to http://www.nic.io/
Domain "IGOR4.IO" - Available
To purchase please go to http://www.nic.io/
igorw commented 12 years ago

Can reproduce, thanks for this report.

igorw commented 12 years ago

It's interesting, the script is actually connecting to the server, but some of the connections get closed immediately. This might be to protect from flooding.

If I add a small delay to each query, I get all results.

igorw commented 12 years ago

And confirmed, if I use igor$n.com I get all results. So that is simply something we cannot fix in the library. It is specific to the io whois server.

umpirsky commented 12 years ago

Ah, great, thanks.

umpirsky commented 12 years ago

But wait, I must get some response anyway, do I? It looks like callback isn't called at all for some queries.

BTW, can I see how did you added small delay? And what did you mean in the last comment when you say it works with igor$n.com?

igorw commented 12 years ago

You don't get a response, the connection is closed. The end callback is called on the connection.

I added a delay by using $loop->addTimer(). And I replaced igor%s.io with igor%s.com and it worked without the delay. Which means the issue is specific to the io whois server.

umpirsky commented 12 years ago

It would be nice if one can handle cases like this (closed connections).

Yes, I noticed that it works for .com domains.

Thanks a lot.

igorw commented 12 years ago

It should currently call your callback with an empty result. So you can handle that case yourself.