PHP WHOIS provides parsed and raw whois lookup of domains and ASN routes. PHP 5.4+ and 7+ compatible
Clone or download


Build Status PHP version Packagist

PHP WHOIS client implementation. Sends the queries directly to the WHOIS services.

Use case

  • Raw and parsed domain lookup
  • Raw and parsed ASN routes lookup
  • Direct queries to TLD/ASN hosts
  • Extending and customizing the default hosts, parsers, etc.


System requirements:
  • PHP >= 5.4 (compatible with 7.* up to nightly)
  • php-intl
  • php-mbstring
  • php-memcached + Memcached server (both optional)
  • Allowed port 43 in firewall
Project requirements:
  • PSR-4 autoloader
composer require io-developer/php-whois

or composer.json:

"require": {
    "io-developer/php-whois": "*"


Domain lookup

How to get summary about domain:

use Iodev\Whois\Whois;

// Creating default configured client

// Checking availability
if (Whois::create()->isDomainAvailable("")) {
    print "Bingo! Domain is available! :)";

// Supports Unicode (converts to punycode)
if (Whois::create()->isDomainAvailable("почта.рф")) {
    print "Bingo! Domain is available! :)";

// Getting raw-text lookup
$response = Whois::create()->lookupDomain("");
print $response->getText();

// Getting parsed domain info
$info = Whois::create()->loadDomainInfo("");
    'Domain created' => date("Y-m-d", $info->getCreationDate()),
    'Domain expires' => date("Y-m-d", $info->getExpirationDate()),
    'Domain owner' => $info->getOwner(),
Exceptions on domain lookup:

use Iodev\Whois\Whois;
use Iodev\Whois\Exceptions\ConnectionException;
use Iodev\Whois\Exceptions\ServerMismatchException;
use Iodev\Whois\Exceptions\WhoisException;

try {
    $info = Whois::create()->loadDomainInfo("");
    if (!$info) {
        print "Null if domain available";
    print $info->getDomainName() . " expires at: " . date("d.m.Y H:i:s", $info->getExpirationDate());
} catch (ConnectionException $e) {
    print "Disconnect or connection timeout";
} catch (ServerMismatchException $e) {
    print "TLD server (.com for not found in current server hosts";
} catch (WhoisException $e) {
    print "Whois server responded with error '{$e->getMessage()}'";
TLD hosts customization:

use Iodev\Whois\Whois;
use Iodev\Whois\Modules\Tld\TldServer;
use Iodev\Whois\Modules\Tld\TldParser;

$whois = Whois::create();

// Define custom whois host
$customServer = new TldServer(".custom", "whois.nic.custom", false, TldParser::create());

// Or define the same via assoc way
$customServer = TldServer::fromData([
    "zone" => ".custom",
    "host" => "whois.nic.custom",

// Add custom server to existing whois instance

// Now it can be utilized
$info = $whois->loadDomainInfo("google.custom");

TLD default/fallback servers:

use Iodev\Whois\Whois;
use Iodev\Whois\Modules\Tld\TldServer;

$whois = Whois::create();

// Add default servers
$matchedServers = $whois->getTldModule()
        ['zone' => '.*.net', 'host' => 'localhost'],
        ['zone' => '.uk.*', 'host' => 'localhost'],
        ['zone' => '.*', 'host' => 'localhost'],

foreach ($matchedServers as $s) {
    echo "{$s->getZone()}  {$s->getHost()}\n";

// Matched servers + custom defaults:
// .uk.*  localhost
// .*.net  localhost
// .net
// .net
// .*  localhost

ASN lookup

How to get summary using ASN number:

use Iodev\Whois\Whois;

// Getting raw-text lookup
$response = Whois::create()->lookupAsn("AS32934");
print $response->getText();

// Getting parsed ASN info
$info = Whois::create()->loadAsnInfo("AS32934");
foreach ($info->getRoutes() as $route) {
        'route IPv4' => $route->getRoute(),
        'route IPv6' => $route->getRoute6(),
        'description' => $route->getDescr(),

Response caching

Some TLD hosts are very limited for frequent requests. Use cache if in your case requests are repeating.


use Iodev\Whois\Whois;
use Iodev\Whois\Loaders\SocketLoader;
use Iodev\Whois\Loaders\MemcachedLoader;

$m = new Memcached();
$m->addServer('', 11211);
$loader = new MemcachedLoader(new SocketLoader(), $m);

$whois = Whois::create($loader);


The project is open for pull requests, issues and feedback. Please read the