PHP WHOIS library: domain availability, registration data and prices in your PHP code

API & DocumentationSDKs, CLI & Libraries·· 182 views· 3 min read

A small PHP library for the free WHOIS of our API. It tells you whether a domain is free or registered, when it expires, its nameservers, what it costs to register and which similar names are free. Handy for a domain search on your website, for example.

What it does

$whois->lookup('example.com') checks a domain and returns a result. On it, isAvailable() and isRegistered() give the status, expiresAt() the expiry date and nameservers() the nameservers.

registerPrice($years) gives the registration price, alternatives() up to 4 similar free names, and registerUrl() the page to register the name. lookupMany checks up to 10 domains in one request.

What you need

PHP 7.4 or newer with the json extension. No other packages: it uses cURL when it is there, and PHP streams when it is not. Without Composer, require the autoload.php of the package.

You do not need a key to start.

Installing, step by step

1 In your project folder, install the package with composer require mozout/php-whois.
2 Run your first lookup with the code below.
3 Check the status with $result->isAvailable() or $result->isRegistered().

use MozOut\Whois\Client;

$whois = new Client();
$result = $whois->lookup('example.com');

The API key and the limits

Without a key you get 60 lookups per hour per IP. With an API key of your account, Sandbox or Production, you get 1,000 per hour per account (resellers: 10,000). Create one in the API Center of My MozOut.

Pass it in the code, with new Client(['api_key' => getenv('MOZOUT_API_KEY')]), or set the MOZOUT_API_KEY environment variable. Once the variable is set, new Client() uses it.

Testing without spending

WHOIS lookups are free, and to raise the limit a sandbox_ key works just as well as a Production one. The package has tests: php tests/run.php runs offline, and php tests/live.php example.com makes real lookups that count towards your hourly limit.

Good to know

Errors: they are exceptions you can catch. ValidationException for an extension we do not sell (extension_not_supported), RateLimitException when you hit the limit (getRetryAfter() tells you how many seconds to wait) and WhoisException for anything else.

Options: currency for prices in another currency of the brand, language (pt or en) for the website links, timeout (15 seconds) and retries.

Extensions: the list of extensions the library knows is in the repository README.

Help

If a lookup fails for no clear reason, open a support ticket and send us what getCorrelationId() returns on the exception. The code is in the php-whois repository, under the MIT license.

Ready to search domains from your PHP code?

Download the latest release

SEE ALSO

WHOIS: what it shows about your domain

Composer on shared hosting

Creating an API key

The repository on MozOut Git

SDKs and integrations, in the API documentation

RECOMMENDED PRODUCT

Register your .com domain

Secure your company name before someone else registers it. from $17.00/yr

Search a domain
Was this answer helpful? Your answer helps us improve this article.