The easiest way to get whois information with PHP – Part 1

I recently finished a project which required me to gather whois information for a large number of domains. I tried using all kinds of APIs to do the trick, but they either offered very limited requests, or weren`t working properly at all. So I started searching for a way to get the whois information with PHP. I`ve tried various approaches, including querying a whois server on port 43, but that required some BASH/Expect scripts and was fairly slow. Then I came across the native Linux “whois” command. If you`re on a unix box you can easily try that: Open terminal and type “whois”. What do you know it works right? From that point forward implementing that in PHP was fairly easy. I just used the shell_exec function and got the content of the response. The solution was fast, didn`t require requests to any external apis and most of all it worked perfectly.


$url = "";

$whoisData = shell_exec("whois {$url}");



In the next part of this tutorial I`ll show you how to create a whois api as a WordPress Plugin. Hope you enjoyed reading that, if you have any questions ask them in the comments below.

If you want to know more about the WHOIS protocol, visit the wikipedia article about it.