Help turn this fsockopen into a curl function instead

$sock = fsockopen('whois.crsnic.net', 43) or die('Error Connecting To Server.');
fputs($sock, "arcadejunk.com\\r\
");
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.

$curlPost[] = "arcadejunk.com\\r\
";
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!!

$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\
");
$data = curl_exec ($ch);
echo $data;

Try this out:


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "whois.crsnic.net");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo $data = curl_exec($ch);

I am not sure whether it works for you or not but this prints the contents of this url.

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.

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

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.

So what is the problem on this:


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "whois.crsnic.net:43");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
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:


curl_setopt($ch, CURLOPT_PORT, 80);