There is 1 bug in gethostbyaddr_timeout() function that king dot macro at gmail dot com posted in the most important line of all, setting the timeout with socket_set_timeout(). It should be:
@socket_set_timeout($handle, intdiv($timeout_ms, 1000), $timeout_ms % 1000);
I'd also make the $dns parameter last and optional and parse it from /etc/resolve.conf (or something else) if not given.