PHP Domain Availability Checking Script


This blog post is old now, the code has been refactored and now must be installed with composer, you can find the new package on packagist.

Skip To…


First of all, This needs to be said, every script that I’ve seen out there that tries to check domain availability simply doesn’t work, sucks or uses an unreliable method that is either too slow or just gives you errors, other than that there is the RoboWHOIS API, which is good for small projects, but it costs money and it’s slow.


I created this script because I needed a quick, decently reliable and FREE way of checking if a domain is available (Not registered) for purchase, the application that I was building at the time that needed this functionality was my domain name generator site (No longer available).


Which randomly generates a string by combining various technology related words then checks to see if the various other TLD’s) is available, it then links to various registrars(GoDaddy, NameCheap and NameSilo) where you get the option to register the domain name, I also added some affiliate links so that I could generate a few dollars if someone chooses to purchase the domain that my site generated for them.


At first I tried the HORRIBLE method of using GetHostByName, which pretty much just tried to get the IP address of the domain name.

The problem with this method is that, a Domain name can be registered and not assigned any IP address, nor point to any server at all.

So when that method seemed to fail very often, I googled around for an API that I could use, and found the RoboWHOIS API, without any other alternative, I purchased a few credits and started to implement this API.


It worked nicely and was reliable, the problem was speed, It was slow as shit when doing multiple requests in a semi-rapid succession(Like checking various TLD’s at the same time), It also ate through credits like crazy, seeing as every user is going to consume one credit per TLD, per Refresh.

Queue the need for a dedicated script for the sole purpose of checking if a domain is avilable, If you’re having the same problem I have, you can leave a thanks and a link to your project in the comments.


Domain Availability Checking Script

=> Code has been moved to GitHub <=


How to use:

Include the file containing the script

$available  will now be either TRUE(if the domain is available) or FALSE(if it is not available).

So now you could use this in a project like this (Replace with whatever domain you want to check).




Have you found a creative way to use this script? Tell us in the comments! :D


Bugs and TODOs:

  • If the WHOIS has some sort of request limiting then my script will always return FALSE.
    • This can be fixed by either implementing  some sort of proxy rotation system into the code.
    • Or by handling this event by adding another field in the $whois_arr  to look for request limiting messages like: “Your requests are too fast, please slow down”.
  • The way the script receives data from the WHOIS server could probably be simplified or improved.
  • The $whois_arr  contains every known TLD, although some of them are missing the WHOIS server and its “Not Found” string.
    • I manually checked the replies from every single WHOIS server that I’ve filled out in the list and copy pasted the “not found” string into the script manually.
    • Some of the TLD’s that was listed in the IANA Database did not have a WHOIS server listed, you might have to do some digging to find those manually.

Credits and License

Script written and created by Helge Sverre.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

If you use this script anywhere or modify it, please link back to my website and send me an email with your work :D


  1. Thanx for the script ..
    could you please help me with a problem i am encountering a problem:

    ” Fatal error: Can’t use function return value in write context in D:\xampp\htdocs\domiancheck\DomainAvailability.php on line 591″

    public function get_tld ($domain) {

    // this checks the domain string to see if it has “www.” included at the end

    /*line591*/ if ( !substr($domain, strpos($domain, “www.”)) || empty(substr($domain, strpos($domain, “www.”))) ) {
    // If “www.” is not found in the domain string then set the offset to 0
    $domain_offset = 0;
    } else {
    // If “www.” is found in the domain string then set the offset to 4
    $domain_offset = 4;

    so what i did to make it work was omit the above code and set $domain_offset = 4;

    is_available($domain) . $domain values i tested for ” “, example ,,

  2. same issue here
    latest version / no code changes:

    Fatal error: Can’t use function return value in write context in DomainAvailability.php on line 586

  3. Hi Helge,

    On the current code on Github (8/11/2014, latest commit c7e6164c9a) , there are some small issues with parenthesis:

    On line 589: if ( !$hasWWW) || empty($hasWWW)) ) {
    should be: if ( !$hasWWW || empty($hasWWW)) {
    (one right parenthesis to much…)

    On line 586: $hasWWW = substr($domain, strpos($domain, “www.”);
    Should be: $hasWWW = substr($domain, strpos($domain, “www.”) );
    (one missing right parenthesis…)

    Sure, on the whole the number of right parenthesis is correct, but that doesn’t do the job!

    After these modifications, the code works perfectly, it’s great.
    I am using it for some testing now.

    However, I have one question (the 1 million dollar one): how to deal with the whois requests limit ?


    1. Arghhhhh, damn, Note to self: always test before committing.
      Fixed the error, tested and committed, thanks a lot :)

      Well I have implemented an “unreliable” check that will run first before querying the whois servers, it uses the gethostbyname() function that will return the same string passed to it if the hostname passed to it does not have an IP( 80% ~of domains will be assigned an IP, … kind of), if
      the function fails, it will fall back to querying the WHOIS server directly, this is to reduce the requests that is sent to the whois server.

      If that is not enough, I would include some sort of proxy rotation scheme:
      1. Scrape a bunch of proxies
      2. Put them in a file (you could create a python script for this)
      3. Create a function in the DomainAvailability class to import the proxies (into an array?)
      4. Rotate them on each query to the whois server.

      If anyone has a better solution I’d love to hear it.

  4. Hello Helge,
    I am testing this script in my wamp server.
    When i use this script for 3 to 4 domains inside a for loop it will take around 30 Seconds to give the results.

    but in your site it only takes a second load results for 9 domains.

    Please give solution so that i can improve the speed like your demo site.


    1. The speed issue might have to do with the fact that you are developing locally, Sometimes even if you’ve got an awesome connection it might be slower than a web host that is located in a Data center and practically has a connection straight into the backbone of the internet, which means that it can send the requests and receive the response a lot faster.

      That is the only thing I can think of to be honest, I didn’t make any other changes to the code on other than put the function in a loop.

  5. Thanks, this is a great script. I was able to successfully implement it with Laravel as a model. Quite powerful. Really appreciate it.
    One question though, how do I find out what or or .in or .pw etc WHOIS servers are? because the common TLDs are not always the case.

    1. Thank you :)

      .in and .pw are already implemented and their whois servers are:
      .in –
      .pw –

      For the domains those are just “glorified subdomains” of the .bd, What I’d do for those kind of special TLD’s is to add them to the list regardless of it being a tld then try to find the whois server that controls the root .db tld, Which I’ve tried to find for awhile not but I can’t seem to get working, but it seems like it’s “official” whois server was

      So to make them work you would have to add these lines to the whois server array:
      ".bd" => array("","MATCH"),
      "" => array("","MATCH"),
      "" => array("","MATCH"),
      "" => array("","MATCH")

      1. Thanks. I looked around the web and I don’t think the .bd tld whois server is This is very confusing. Thanks for this awesome script. Works like a charm. I had tried many other things.

        1. @yosuf kamal bhai,

          help me bro.i can’t still figure it out!!! .bd tld server may be wrong…its not working for me..please paste the right configure!!

          1. Hi, I’m very sorry to inform you that BTCL has yet to develop and open API through which you can check availability of *.bd domains. No wonder. So this is not going to happen anytime soon. You cant even check the availability in their website, you can only find the information about the sites that already exist. stupid, no?

  6. Hi Mr. Helge;
    I have to say thank you for this cool programm.
    I want to check .ir domain but all kind of .ir domains get the same result and that’s FALSE…
    This is my code…
    Would you help me?


    include (“domain_availability/DomainAvailability.php”);

    $domain = trim( $_POST[‘domain_name’] );

    $Domain_init = new DomainAvailability(true);

    $available = $Domain_init->is_available($domain);

    if ( $av… ) {}
    else {}

          1. May be it’s because of my English comprehension, but I thought you said “…You’ll be update the code for support .ir domains…”
            Actually I checked the whois servers in your code and every thing seems to be right there.
            There is a whois server for .ir domains in this line:
            “.ir” => array(“”,”MATCH”),
            but still I can’t check ir domain.
            It’s very kind of you if you help me out…
            Take care…

  7. Hows this working nowadays? Can it check availability for all international tld? What if you check 300k in 1 day, will the whois end up limiting you, that would be a big problem.

  8. aw ok, gotcha, ya Im actually looking for a solid script or bot to check internation tld availabilities. Im so sick of these programs that are either slow, limit, freeze, etc. Since Im on a large scale I also need consistency, efficiency. Sooo, Im still on the hunt. Thanks for your reply tho

    1. Well if you are checking on a large scale you will need proxies as most whois servers rate-limit individual IP addresses to x requests / second, by using proxies you can just switch to another IP when you’ve hit your limit, I am planning to write a program or class that supports that kind of large scale checking, but we’ll see.

  9. Hi Helge,
    i’m appreciate your php files, can you please make include files,e.g domain.txt instead of write domains on example.php.
    Thanks for your help

  10. Not working at all!
    Fatal error: Uncaught exception ‘Exception’ with message ‘Invalid domain extension’ in /public_html/AvailabilityService.php:471

  11. get error while running example.php file

    Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\kanu\demo\Domain-Availability-master\example.php on line 2

    Fatal error: require(): Failed opening required ‘vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\kanu\demo\Domain-Availability-master\example.php on line 2

  12. I think I’m doig something wron as I am only getting a blank page when I try to run the script using the example page.

    Here is the code I’m using

    require (‘src/AvailabilityService.php’);
    $Domain = new DomainAvailability;
    $available = $Domain->is_available(“”);

    if ($available) {
    echo “The domain is not registered”;
    } else {
    echo “The domain is registered”;

    1. I think you forgot to use the namespace, try this:

      1. thanks, though I think the problem was that I was trying to run it as a script instead of using composer.json

        I dont have shell access to the account, is there any way of using this as a script?

  13. I am running script on a localhost at the moment and trying to get this script to work (I am fairly new to php).
    I keep getting this error:
    Fatal error: Class ‘HelgeSverre\DomainAvailability’ not found in C:\wamp\www\transit\products – Copy.php on line 53
    this is the code i am using:


    if ($available) {
    echo ‘The domain is not registered’;
    } else {
    echo ‘The domain is registered’;

    Any help would be appreciated, thanks :)

    1. sorry, code:

      require (‘src/AvailabilityService.php’);

      $Domain = new HelgeSverre\DomainAvailability();

      $available = $Domain->is_available(‘’);

      if ($available) {
      echo ‘The domain is not registered’;
      } else {
      echo ‘The domain is registered’;

  14. Hello

    Helge Sverre Hessevik Liseth. I have one problem. When i check domain name on localhost like use xampp then i works fine, but when i upload it on server then its not works. But why?

  15. Hi, Thanks for code.
    It was working till 2 days ago although with few wrong answers. but now I get false all the time. (isAvailable function)
    Any help will be appreciated

    1. Have to say but now again I get the correct answer!! Is there anything to do to handle this condition? Also furthermore I’m in Iran, is it possible it happens do to boycott?? :| :((

  16. Nice API, but i wonder..
    What is the difference between this API/whois servers, and others pay per use?
    And between this and a registrar api, like GoDaddy?

    What is the difference in term of fresh data retrieved between these methods for .com?

  17. Hello, Helge. I just downloaded the Zip file from I tried to deploy according to the file example.php but even when running example.php I get this error:

    Warning: require(./vendor/autoload.php): failed to open stream: No such file or directory in /path-to/example.php on line 9

    When I try to run the app from my own page then I get this error:

    Parse error: syntax error, unexpected ‘use’ (T_USE) in /path-to/myfile.php on line ## – where ## is line is this:

    use Helge\Loader\JsonLoader;

    I am pretty sure I am missing a lot of things. Could you please enlight me a little bit? I do would like to see how your application works.

    Thank you very much in advance for your help.

      1. Hello, Helge. Thank you for your kind attention and help. I will first try to install Composer on my shared hosting account – I could tell myself that it won’t be an easy task but I am already talking with my hosting provider.

      2. Hola, Helge! Sorry, mate, but the Composer thing is not working at all for me. I would like to try the other variant but I am not sure where I should write down this code:

        “require”: {
        “helgesverre/domain-availability”: “~0.2.0”

        I mean, should I add it at the top of the example.php-like file in my working directory or should I add it somewhere else?

        Thank you so very much for your kind attention and help and please, excuse my lack of knowledge for this.

  18. Hello mr.helge

    i got fatal error while it run n my local host & error like this :

    Warning: require(vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Domainav\example.php on line 9

    Fatal error: require(): Failed opening required ‘vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\Domainav\example.php on line 9
    my code is:

    Domain Availability Checker

  19. Hi, I have installed Composer globally, and when I try to run the command:

    composer -s dev helgesverre/domain-availability

    I get:

    Command “dev” is not defined.

      1. Hi thanks for the reply. Is it supposed to be composer require –dev helgesverre/domain-availability (with 2 dashes before dev)? For some reason bth give me errors but I noticed your gitgub page has 2 dashes before dev.

        The error I get when I run the command with 2 dashes is:

        Your requirements could not be resolved to an installable set of packages.

        Problem 1
        – jeremykendall/php-domain-parser 3.0.0 requires ext-intl * -> the requested PHP extension intl is missing from your system.
        – helgesverre/domain-availability 0.2.2 requires jeremykendall/php-domain-parser ^3.0 -> satisfiable by jeremykendall/php-domain-parser[3.0.0].
        – Installation request for helgesverre/domain-availability ^0.2.2 -> satisfiable by helgesverre/domain-availability[0.2.2].

      2. Hello, I finally managed to activate the intl extension. Now when I go to the page I have created (just uses your sample code from the ‘Usage’ section of your github page), I get the following error:

        Uncaught exception ‘Exception’ with message ‘No WHOIS entry was found for that TLD’ in /Applications/XAMPP/xamppfiles/htdocs/domainChecker/vendor/helgesverre/domain-availability/src/Service/DomainAvailability.php:50 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/domainChecker/index.php(14): Helge\Service\DomainAvailability->isAvailable(‘’) #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/domainChecker/vendor/helgesverre/domain-availability/src/Service/DomainAvailability.php on line 50

      3. I am new in laravel 5. Now I want to implement domain name concept in our live project.
        Using our website customers can select template and release their own website. So, for that website we want to give an option for selecting domain name for customers. That time our website will connect with namecheap site. How to do this? Can u give one idea? I am new in IT industry also..Please help me sir.

  20. I have download from Github and i try it, but the warning show there is no file autoload.php

    Warning: require(./vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\domain-availability\example.php on line 9

    Fatal error: require(): Failed opening required ‘./vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\domain-availability\example.php on line 9

    1. download compreser install it, open comand line go to your projet directory (in command line) user <>

      and test it again

  21. Hello helge
    could you help me please. I got fatal error after i’ve run in localhost, the error is like this :

    Fatal error: Call to undefined function Pdp\idn_to_ascii() in C:\xampp\htdocs\domain-availability\vendor\jeremykendall\php-domain-parser\src\Pdp\Parser.php on line 318


  22. why if i trying that i have error message, like this “Fatal error: Class ‘DomainAvailability’ not found in C:\xampp\htdocs\TA\UPDATE_4ICU\lala.php on line 35”

    maybe you can help me. thanks

  23. Good morning Helge Sverre Hessevik Liseth !
    Please i have this error <>, in fait i need to use the script in my website o allow user to chose their domain for hosting plan.

    Please can you help me to understand why that error ?

Leave a Reply

Your email address will not be published. Required fields are marked *