【发布时间】:2013-05-30 19:00:39
【问题描述】:
我有一个代码,我从数据库中获取域并通过 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
}
【问题讨论】:
-
您正在处理多少条记录?你能定义“慢”吗,你确定不是mysql慢吗?
-
我认为问题在于 DNS 请求的持续时间。尝试使用不同的(更好的缓存)DNS 服务器来加快重复请求的速度。
-
从慢我的意思是每秒大约 1-2 个请求。 @RyanNaddy
-
@Stasik 正确假设。该怎么做?
-
@user2419169 你用的是什么DNS?首先,尝试将您的操作系统的 DNS 服务器更改为其他一些,也许是 Google 的(8.8.8.8)?下一步是获取自己的 DNS 缓存,这取决于操作系统(例如,对于 Ubuntu askubuntu.com/questions/22750/best-way-to-set-up-dns-caching)。
标签: php performance mx-record