SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot allstar's Avatar
    Join Date
    Sep 2005
    Location
    in my box.
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help turn this fsockopen into a curl function instead.

    Code:
    $sock = fsockopen('whois.crsnic.net', 43) or die('Error Connecting To Server.');
    fputs($sock, "arcadejunk.com\r\n");
    while( !feof($sock) ) { $buffer .= fgets($sock,1024); }
    fclose($sock);
    Is there a way to change the above code into a curl function? cUrl works faster and can do more inquires then fsockopen can do. I would like to change my whois lookup routine into a curl whois lookup routine.

    Please, help.

    I have been tring to use this with no luck.

    Code:
    $curlPost[] = "arcadejunk.com\r\n";
    if(!$ch = curl_init('whois.crsnic.net')) {
       echo "Could not connect to whois.crsnic.net";
        return;
    }
    curl_setopt($ch, CURLOPT_PORT, 43);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    //curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $curlPost);
    $data = curl_exec($ch);
    
    echo "<pre>";
      print_r(curl_getinfo($ch));
      echo "<br />cURL error number: " .curl_errno($ch)."<br />";
      echo "<br />cURL error: " . curl_error($ch)."<br />";
     curl_close($ch);
     echo "<br />$data<br />";
    echo "</pre>";
    I did notice a post on the libcurl website saying that the curlopt_port had a bug in it where it would not set the port correctly.

    The version that is running.
    libcurl/7.15.3 OpenSSL/0.9.7a zlib/1.2.1.2 libidn/0.5.6
    //EDIT*******

    Found it!!

    Code:
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"whois.crsnic.net:43");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "arcadejunk.com\r\n");
    $data = curl_exec ($ch);
    echo $data;
    Last edited by allstar; Feb 18, 2007 at 00:37.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this out:
    PHP Code:
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"whois.crsnic.net");
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    echo 
    $data curl_exec($ch); 
    I am not sure whether it works for you or not but this prints the contents of this url.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Addict nameslot's Avatar
    Join Date
    Jan 2006
    Posts
    305
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have done a whois lookup rountine on my domain name tools page of the website.

    http://www.nameslot.com/nametools.php

    If you are interested in this code then let me know. But I can tell you that it is also using fsockopen.

  4. #4
    SitePoint Zealot allstar's Avatar
    Join Date
    Sep 2005
    Location
    in my box.
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rajug: That defaults to port 80, which will not work.

    nameslot: I have fsockopen working. That is not the problem.

    Here is the reason why I want to use cUrl instead of the fsockopen.

    Performance Comparison*

    10 per minute for fopen/fread for 100 HTTP files
    2000 per minute for PHP/CURL for 2000 HTTP files

  5. #5
    SitePoint Addict nameslot's Avatar
    Join Date
    Jan 2006
    Posts
    305
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay so in short you want the contents of the given page in the $buffer variable which now is being done by fsockopen and you want to get the same thing using cURL.

    Right.

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by allstar View Post
    rajug: That defaults to port 80, which will not work.
    So what is the problem on this:
    PHP Code:
    $ch curl_init();
    curl_setopt($chCURLOPT_URL"whois.crsnic.net:43");
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    echo 
    $data curl_exec($ch); 
    I think it is working for me here which shows this text in response.
    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 "GET / HTTP/1.1". >>> Last update of whois database: Mon, 19 Feb 2007 04:12:02 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. TERMS OF USE: You are not authorized to access or query our Whois database through the use of electronic processes that are high-volume and automated except as reasonably necessary to register domain names or modify existing registrations; the Data in VeriSign Global Registry Services' ("VeriSign") Whois database is provided by VeriSign for information purposes only, and to assist persons in obtaining information about or related to a domain name registration record. VeriSign does not guarantee its accuracy. By submitting a Whois query, you agree to abide by the following terms of use: You agree that you may use this Data only for lawful purposes and that under no circumstances will you use this Data to: (1) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via e-mail, telephone, or facsimile; or (2) enable high volume, automated, electronic processes that apply to VeriSign (or its computer systems). The compilation, repackaging, dissemination or other use of this Data is expressly prohibited without the prior written consent of VeriSign. You agree not to use electronic processes that are automated and high-volume to access or query the Whois database except as reasonably necessary to register domain names or modify existing registrations. VeriSign reserves the right to restrict your access to the Whois database in its sole discretion to ensure operational stability. VeriSign may restrict or terminate your access to the Whois database for failure to abide by these terms of use. VeriSign reserves the right to modify these terms at any time. The Registry database contains ONLY .COM, .NET, .EDU domains and Registrars.
    I am not sure about this message/text but it should work like this specifying the port in the address.

    You can also specify your port like this:
    PHP Code:
    curl_setopt($chCURLOPT_PORT80); 
    Last edited by Raju Gautam; Feb 18, 2007 at 22:51.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •