Looping domain availability check - need help please

Discussion in 'PHP' started by SuPrAiCeR69, Dec 21, 2010.

  1. #1
    I have an example below from the registrar and when implemented (in a loop) it takes between 500ms to 1s between checks.
    I need it to run as quickly as possible, whether it be through curl or without. It seems curl takes forever between checks.

    I only need the script to check one domain.

    1. Is there a way to loop a post of $url and return the output foreach results, much quicker than 500ms per check? Alternative to curl?
    2. Running through curl, but checking the domain availability in such a way where it does not lag in checks?

    I can post the variable $domainslist (an array with a limit of 20 domains , or in my case, 20 copies of the same domain), it will exec curl, check availability on each and output with only 0.00022 avg lag between checks. When I loop the curl exec it will then run the above array of domain in lightning speed time, lag 5-8 seconds and execute the 20 again in lightning speed time.

    3. Is there some way to stop that 5-8 second lag between the checks of each array? I assume not, only because it must reconnect curl..

    Any help checking availability in minimal time, no matter which method, would be very much appreciated! Thanks!

    Code without loop

    
    <?php
    
    
    
        function GetCurlPage ($pageSpec)
    
        {
    
          $ch = curl_init($pageSpec);
    
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
          curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    
          $tmp = curl_exec ($ch);
    
          curl_close ($ch);
    
          $tmp = preg_replace('/(?s)<meta http-equiv="Expires"[^>]*>/i', '', $tmp);
    
          $tmp = explode('<br>', $tmp);
    
          echo $tmp[0];
    
          echo "<br>";
    
          echo $tmp[1];
    
          echo "<br>";
    
          return $tmp;
    
        }
    
    
    
    $returnUrl = "http://www.mysite.com/check.php";
    
    $url = "https://www.apisite.com/availability/check.php?domain=testdomain&suffixes=.com";
    
    $output = GetCurlPage("$url");
    
    
    
    ?>
    
    
    PHP:
     
    SuPrAiCeR69, Dec 21, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    what data are you trying to get from that url: domain expiration date? I may know a faster method of getting the data:)
     
    shofstetter, Dec 21, 2010 IP
  3. SuPrAiCeR69

    SuPrAiCeR69 Peon

    Messages:
    216
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Available or not available.
    Any help would be much appreciated! Quickest method and example please? :) Thanks
     
    SuPrAiCeR69, Dec 21, 2010 IP
  4. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #4
    $domain = "someone.com";
    $whois = shell_exec("whois ".$domain);

    if(substr_count($whois,"No Match For ") != 0){
    echo "domain is not registered";
    }else{
    if(substr_count($whois,"Expires on..............:") != 0){
    $expires = trim(get_string_between($whois,""Expires on..............:","Record last updated on..:"));
    }else{
    if(substr_count($whois,"Expires on:") !=0){
    $expires = trim(get_string_between($whois,""Expires on:","Last Updated on:"));
    }
    }
    }

    well you get the idea whois is installed on most linux distros and provides a vey fast lookup :)

    function get_string_between($string, $start, $end){
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0) return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
    }
     
    shofstetter, Dec 21, 2010 IP
  5. SuPrAiCeR69

    SuPrAiCeR69 Peon

    Messages:
    216
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Output is blank :(

    How can I use shell_exec with my original example to output Available or not available?

    Thanks
     
    SuPrAiCeR69, Dec 21, 2010 IP
  6. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #6
    whois is a linux command line utility for doing a whois record search. try executing just the following code

    <?php
    $string = shell_exec("whois guppy.com");
    echo str_replace("\n","<br/>",$string);
    ?>

    if your host has the whois program installed on there server you will get the registration information for guppy.com or a message stating no match if the domain is not registed. here is some example output from the whois command:

    
    stephen@ubuntu:~$ whois -H fish.com
    
    Whois Server Version 2.0
    
    Domain names in the .com and .net domains can now be registered
    with many different competing registrars. Go to http://www.internic.net
    for detailed information.
    
       Domain Name: FISH.COM
       Registrar: NETWORK SOLUTIONS, LLC.
       Whois Server: whois.networksolutions.com
       Referral URL: http://www.networksolutions.com
       Name Server: UDNS1.ULTRADNS.NET
       Name Server: UDNS2.ULTRADNS.NET
       Status: clientTransferProhibited
       Updated Date: 13-jul-2010
       Creation Date: 05-oct-1993
       Expiration Date: 04-oct-2016
    
    >>> Last update of whois database: Wed, 22 Dec 2010 07:45:04 UTC <<<
    
    NOTICE: The expiration date displayed in this record is the date the 
    registrar's sponsorship of the domain name registration in the registry is 
    currently set to expire. This date does not necessarily reflect the expiration 
    date of the domain name registrant's agreement with the sponsoring 
    registrar.  Users may consult the sponsoring registrar's Whois database to 
    view the registrar's reported date of expiration for this registration.
    
    
    The Registry database contains ONLY .COM, .NET, .EDU domains and
    Registrars.
    
    Get a FREE domain name registration, transfer, or renewal with any annual hosting package.
    
    http://www.networksolutions.com
    
    Visit AboutUs.org for more information about FISH.COM
    <a href="http://www.aboutus.org/FISH.COM">AboutUs: FISH.COM </a>
    
    
    
    
    Registrant:
    TABcom LLC FKA PetsUnited LLC
       ATTN FISH.COM
       care of Network Solutions
       PO Box 459
       Drums, PA.  US  18222
       
    
       Domain Name: FISH.COM
    
       ------------------------------------------------------------------------
       Promote your business to millions of viewers for only $1 a month
       Learn how you can get an Enhanced Business Listing here for your domain name.
       Learn more at http://www.NetworkSolutions.com/
       ------------------------------------------------------------------------
    
       Administrative Contact, Technical Contact:
          McCormick, Clarice		b856e38b8zx@networksolutionsprivateregistration.com
          PetsUnited, LLC
          ATTN FISH.COM
          care of Network Solutions
          PO Box 459
          Drums, PA 18222
          US
          570-708-8780
          
    
       Record expires on 04-Oct-2016.
       Record created on 05-Oct-1993.
       Database last updated on 22-Dec-2010 02:22:59 EST.
    
       Domain servers in listed order:
    
       UDNS1.ULTRADNS.NET           
       UDNS2.ULTRADNS.NET           
    
    This listing is a Network Solutions Private Registration. Mail
    correspondence to this address must be sent via USPS Express Mail(TM) or
    USPS Certified Mail(R); all other mail will not be processed. Be sure to
    include the registrant's domain name in the address.
    
    
    Code (markup):

    and here is output for a domain name not yet registered:

    
    stephen@ubuntu:~$ whois -H blablablaxyz123.com
    
    Whois Server Version 2.0
    
    Domain names in the .com and .net domains can now be registered
    with many different competing registrars. Go to http://www.internic.net
    for detailed information.
    
    No match for "BLABLABLAXYZ123.COM".
    >>> Last update of whois database: Wed, 22 Dec 2010 07:48:21 UTC <<<
    
    NOTICE: The expiration date displayed in this record is the date the 
    registrar's sponsorship of the domain name registration in the registry is 
    currently set to expire. This date does not necessarily reflect the expiration 
    date of the domain name registrant's agreement with the sponsoring 
    registrar.  Users may consult the sponsoring registrar's Whois database to 
    view the registrar's reported date of expiration for this registration.
    
    
    The Registry database contains ONLY .COM, .NET, .EDU domains and
    Registrars.
    
    
    Code (markup):
    the shell_exec() function executes an external program and returns its output as a string so you could also do things like fetching the contents of a webpage like this:
    $webpage = shell_exec("wget -qO- http://somesite.com");

    :)

    The code I posted before is incomplete I was just using it as an example of how you could scrape the output of the whois command for things like the domain expiration date or to see if it has been registered or not :)
     
    shofstetter, Dec 21, 2010 IP