Incomplete WHOIS record is returned when checking gov.uk domains
Support for checking Gov.uk domains was added in 2b2e539f, however it seems that since then there has been a change in the output format of the whois.ja.net
WHOIS server, or a change in PHP, which is causing only partial WHOIS responses to be received by fread()
. The result of this is that the expiry date for Gov.uk domains cannot be checked.
The whois.ja.net
server outputs WHOIS data in a format different to most other servers. For example:
Domain:
example.gov.uk
Registered For:
Ministry of Example
...
A hexdump of the above shows that there are two line feed (0a
) characters between the end of example.gov.uk
and Registered For
:
00000010 6f 76 2e 75 6b **0a 0a** 52 65 67 69 73 74 65 72 65 |ov.uk..Registere|
The two line feed characters seem to be causing trouble for fread()
when used in non-blocking mode, as it causes the retrieved WHOIS response to terminate after the first line feed. This results in the following incomplete data being passed to parseExpiry()
:
Domain:
example.gov.uk
The fix for this comes in two parts:
-
Enabling stream blocking mode with
stream_set_blocking($whois, true)
(or just not specifying the blocking mode at all, astrue
is the default). This will force the full read request to be satisfied, rather than returning early when it encounters the double line feed. -
Replacing
fread()
withstream_get_contents()
, to read the full stream content rather than just until an EOF is encountered or a packet becomes available.
I'm going to conduct further testing on this fix as the effect it has on non Gov.uk domains is currently not fully understood, and there may be other downsides to enabling blocking mode and using stream_get_contents()
.