You can cache the output of getmxrr
to ensure your not doing the same operation for already validated domains.
assuming you have configured and install memcache. You can replace your lookup with this function
function domain_found($domain) {
$memcache_obj = new Memcache;
$memcache_obj->connect('localhost', 11211);
$var = $memcache_obj->get($domain);
if ($var == "found") return true;
if ($var == "notfound") return false;
getmxrr($domain,$result);
if (empty($result)) {
$memcache_obj->put($domain, 'notfound');
return false;
} else {
$memcache_obj->put($domain, 'found');
return true;
}
}
You can ofcourse work this inside a class if you like, and optimize other value elements. This serves as a proof of concept code.