Topic: More error checking in the fsockopen stage (Read 1346 times)
Google dot what?
Posts: 2
16 credits Members referred : 0
« on: Oct 25, 2006, 07:57:38 PM »
The script is very useful - better than others I've found on the internet. I've been trying it out, and sometimes the fsockopen fails to open a socket. The domain cannot be checked, but currently the domain comes back as registered rather than as an error.
Here are places I've made a few changes to add error checking. Hopefully people can follow this. I've used the scripts since, but mostly the multi_whois_list, so there could be some errors introduced with other ways of checking the domains.
I hope this is useful!
David. ---------------------------------------------------- In the whois_class.php, at top of class, add:
Code:
var $success = false;
In the whois_class.php, function get_whois_data (indentation also changed in this copy, but that's not important. Also, I used the socked all the time, not just on Windows, but again that doesn't affect this change):
if (!$connection) { unset($connection); $this->success = false; $this->msg = "Can't connect to the server!"; return; } else { sleep(2); fputs($connection, $this->whois_param.$this->compl_domain."\r\n");
$buffer = array(); while (!feof($connection)) { $buffer[] = fgets($connection, 4096); } fclose($connection); } if (count($buffer) > 0) { //print_r($buffer); $this->success = true; return $buffer; } else { $this->success = false; $this->msg = "Can't retrieve data from the server!"; }
In the whois_class.php, function check_only:
Code:
function check_only() { //Return values 1 - not registered, 0, already registered, -1 connection error.
$data = $this->get_whois_data(); if (is_array($data) && $this->success) { foreach ($data as $val) { if (eregi($this->free_string, $val)) { return 1; } } return 0; } else { $this->msg = "Error, please try it again."; return -1; } }
In the whois_class.php, function process:
Code:
function process() { if ($this->create_domain()) { if ($this->full_info == "yes") { $this->get_domain_info(); } else { $result = $this->check_only(); if ($result == 1) { $this->msg = "The domain name: <b>".$this->compl_domain."</b> is free."; return true; } elseif ($result == 0) { $this->msg = "The domain name: <b>".$this->compl_domain."</b> is registered"; return false; } else { $this->msg = "There was something wrong, try it again."; } } } else { $this->msg = "Only letters, numbers and hyphens (-) are valid!"; } }
In multi_whois_list:
Code:
function create_dom_list() { if ($this->create_domain()) { $result = $this->check_only(); if ($result == 1) { $this->dom_str .= "<b>".$this->compl_domain."</b> is free.<br>\n"; } elseif ($result == 0) { $this->dom_str .= "<b>".$this->compl_domain."</b> is registered"; $this->dom_str .= " - <a href=\"multi_whois_detail.php?det=".$this->compl_domain."\" target=\"_blank\">Detail</a><br>\n"; }else{ $this->dom_str .= "<b>".$this->compl_domain."</b> Error checking this domain. Please try it again.<br>\n"; } } else { $this->msg = "Only letters, numbers and hyphens (-) are valid!"; } }
« Last Edit: Oct 26, 2006, 01:18:50 AM by difdif »
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6277
38488 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Oct 26, 2006, 01:11:40 AM »
Thanks for your suggestions to make this class better!
It's funny I got some function today from Nick how to parse whois results for browser only whois and it looks like a good idea to combine both features to make from them a rock solid class (you're right I doesn't like the other whois scripts, they are the reason that I wrote this class)
Google dot what?
Posts: 2
16 credits Members referred : 0
« Reply #2 on: Oct 26, 2006, 01:28:13 AM »
Hi olaf,
I've made a couple of changes by editing my original code posting above - there was a mistake, and a way to increase efficiency by calling $this->check_only() fewer times.
A couple of other ideas I have found useful:
1) Using non-blocking mode for the fsockopen, to speed things up if a server is busy or down. Also a timeout of 10 seconds on the fsockopen.