io-developer / php-whois

PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 8.0 compatible (5.4+ old versions)
MIT License
439 stars 117 forks source link

Connection timeout with bulk request at a specific nameserver #184

Closed sirkokoenig closed 2 years ago

sirkokoenig commented 2 years ago

PHP-Whois version: 4.1.6

PHP version: 8.0

Description
When I make over 8-10 request in a foreach loop to a specific whois server (in this case whois.namesilo.com) , I get a timeout error: fsockopen(): Unable to connect to whois.namesilo.com:43 (Connection timed out) Also it tries for a long time and then the script runs in php timeout.

How to reproduce
Make a foreach and choose minimum 8-10 domains from namesilo.

Possible Solution
Is it possible to set a shorter timeout on this request here, to avoid that the script runs in timeout? Or someone has an idea to avoid that I get the connection timeout at whois.namesilo.com? It seems that the server from then stop accepting connections for short time blocks, if request come too fast.

Additional context
/XXX/htdocs/XXXXXX/vendor/io-developer/php-whois/src/Iodev/Whois/Loaders/SocketLoader.php:57

bessone commented 2 years ago

Most whois servers do not accept calls that are too close, often after a certain number of calls they block the IP for a few minutes.

This also happens when trying to quickly make many calls directly from the whois command via the shell.

Obviously not all whois servers have the same rules, but I have tested this on many, to solve I put a sleep between one call and the other when I do bulk checks.

I tried to make 5 calls to the whois.namesilo.com server from the shell, within 1 second of each other and my ip was blocked refusing further calls.

io-developer commented 2 years ago

In that case list of proxies should be used (when lots of requests in short period of time needed) Or a custom Loader with proxy list support

CurlLoader supports proxy opts - https://github.com/io-developer/php-whois#proxy-with-socks5