速度php getmxrr()函数用于处理百万条记录

时间:2013-05-30 19:00:40

标签: php performance mx-record

我有一个代码,我从数据库中获取域并通过PHP getmxrr函数传递它们。然后我将结果存储在数据库中。但这个过程非常缓慢。有什么方法可以加快速度吗?

$stmt = $link->prepare($sql);
$stmt->execute();
$row = $stmt->fetchAll();
foreach ($row as $value) {
    $domain = $value[0];

    //getmxrr doesn't work without this
    $string = preg_replace('/\s+/','',$domain); 

    if (getmxrr($string,$mxrecords)){        

        if(isset($mxrecords[0])){
        $mx = $mxrecords[0];} else $mx = "False";
    }
    else{
        $mx = "NULL";
    }
    $stmt1->execute();    //inserting the results in DB

}   

1 个答案:

答案 0 :(得分:0)

我认为问题是DNS请求的持续时间。尝试使用不同的(更好的缓存)DNS服务器来加速重复发生的请求。

首先,尝试将您的操作系统的DNS服务器更改为其他一些,可能是谷歌服务器(8.8.8.8)?下一步是获取自己的DNS缓存,它取决于操作系统(例如,对于Ubuntu / Linux https://askubuntu.com/questions/22750/best-way-to-set-up-dns-caching)。