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
437 stars 117 forks source link

Keep getting "Disconnect or connection timeout" exception #175

Closed joho1968 closed 2 years ago

joho1968 commented 2 years ago

PHP-Whois version: 4.1.4

PHP version: 7.4.3

Description
I keep getting a "Disconnect or connection timeout" exception, regardless of the domain I use (.se .com .nu etc). There's nothing blocking outgoing traffic.

I'm just using a simple piece of testing code like so:

$whois = Factory::get()->createWhois();
$response = $whois->lookupDomain('google.com');

Is there a specific module or .php file in which I can start looking for the problem, given the type of the exception?

bessone commented 2 years ago

Is port 43 open? Try checking a plain whois from the shell of the same machine. it's working?

Maybe a traceroute to whois server can help too.

joho1968 commented 2 years ago

Yes, regular WHOIS works, regardless of using a domain name or an IP address. Also regardless of TLD.

Is there a place in the code I can add debug output to, in an attempt to catch this?

bessone commented 2 years ago

Look on SocketLoader class where the socket connection is opened https://github.com/io-developer/php-whois/blob/5b84e30c0a02c8abdbfa49adaae28c7aefad54b1/src/Iodev/Whois/Loaders/SocketLoader.php#L9

joho1968 commented 2 years ago

OK, found it :-)

For security reasons fsockopen() is on the list of disabled functions. It works if I remove it from the list.

The code should (IMHO) check for this somewhere, and possibly throw an exception to the effect of "Required functions have been disabled in PHP configuration".

bessone commented 2 years ago

Disabled where? fsockopen is a good old function available from early years of PHP, never found it on my standard installation (servers or docker images). https://www.php.net/manual/en/function.fsockopen.php

I think check for it is outside the scope of this library. Connection error is enough The connection error is enough, it explains that something above (from the server to the network) is preventing communication and the error must be looked for elsewhere.

joho1968 commented 2 years ago

Disabled by putting it in the configuration directive "disable_functions". In our environment, we lock down PHP as much as possible. It's better to be strict and open when required, and in many "standard web hosting environments", it's not needed :-)

You're probably right about the scope. It was just an idea to maybe save others from scratching their heads :-)

Thanks for your time on this issue though. Much appreciated.