Skip to content

PHP WHOIS client provides parsed and raw-text whois lookup info for domains

License

Notifications You must be signed in to change notification settings

jas8522/php-whois

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

101 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP WHOIS

PHP WHOIS client implementation. Provides raw-text and parsed answers. Sends WHOIS queries to real service via port 43

Build Status PHP version Packagist Packagist

Requirements

  • PHP >= 5.4 (compatible with 7.0 up to nightly)
  • intl

Installation

Via Composer cli command

composer require io-developer/php-whois

Or via composer.json

"require": {
    "io-developer/php-whois": "^2.3.0"
}

Usage

Whois client creation

<?php

require_once '../vendor/autoload.php';

use Iodev\Whois\Whois;

$whois = Whois::create();

Domain availability

<?php

use Iodev\Whois\Whois;

if (Whois::create()->isDomainAvailable("google.com")) {
    echo "Bingo! Domain is available! :)";
}

Domain lookup

<?php

use Iodev\Whois\Whois;

$response = Whois::create()->lookupDomain("google.com");
echo $response->getText();

Parsed domain info

<?php

use Iodev\Whois\Whois;

$info = Whois::create()->loadDomainInfo("google.com");
echo "Domain created: " . date("Y-m-d", $info->getCreationDate());
echo "Domain expires: " . date("Y-m-d", $info->getExpirationDate());
echo "Domain owner: " . $info->getOwner();

Advanced usage

Сommon client powered by memcached

<?php

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

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

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

Complete domain info loading

<?php

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

$whois = Whois::create();
try {
    $info = $whois->loadDomainInfo("google.com");
    if (!$info) {
        echo "Null if domain available";
        exit;
    }
    echo $info->getDomainName() . " expires at: " . date("d.m.Y H:i:s", $info->getExpirationDate());
} catch (ConnectionException $e) {
    echo "Disconnect or connection timeout";
} catch (ServerMismatchException $e) {
    echo "Domain zone servers (.com for google.com) not found in current ServerProvider whois hosts";
}

Original WHOIS answer via lookup

<?php

use Iodev\Whois\Whois;

$response = Whois::create()->lookupDomain("google.com");
echo $response->getText();

Original WHOIS answer via domain info

<?php

use Iodev\Whois\Whois;

$info = Whois::create()->loadDomainInfo("google.com");
$resp = $info->getResponse();

echo "WHOIS response for '{$resp->getDomain()}':\n{$resp->getText()}";

Сustom whois hosts

<?php

use Iodev\Whois\Server;
use Iodev\Whois\Whois;
use Iodev\Whois\Parsers\CommonParser;

$whois = Whois::create();

// Define custom whois host
$customServer = new Server(".co", "whois.nic.co", false, new CommonParser());

// Or define the same via assoc way
$customServer = Server::fromData([
    "zone" => ".co",
    "host" => "whois.nic.co",
]);

// Append to existing provider
$whois->getServerProvider()->addOne($customServer);

// Now you can load info
$info = $whois->loadDomainInfo("google.co");

var_dump($info);

About

PHP WHOIS client provides parsed and raw-text whois lookup info for domains

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%