Php 找到一个更快的函数,然后;gethostbyname";?
我使用mysqlDB在xampp下运行脚本 我检查域名是否有ip 问题是,我必须从一个MySQL数据库中检查100000多个域名 函数“gethostbyname”工作得很好,但我的解决方案太慢了Php 找到一个更快的函数,然后;gethostbyname";?,php,Php,我使用mysqlDB在xampp下运行脚本 我检查域名是否有ip 问题是,我必须从一个MySQL数据库中检查100000多个域名 函数“gethostbyname”工作得很好,但我的解决方案太慢了 while($row = mysqli_fetch_array($db_res)) { // get the DB domainnames entrys if (empty($row['status'])) { $items[] = $row['domainnames'];
while($row = mysqli_fetch_array($db_res)) { // get the DB domainnames entrys
if (empty($row['status'])) {
$items[] = $row['domainnames'];
}
foreach ($items AS $domain) {
if ( gethostbyname($domain) != $domain ) {
do somthing.....
}
}
}
如何加快速度?看起来,当您的while循环迭代时,它使用上一次迭代的$items-这将浪费时间-因此请尝试此版本(将foreach放入if:
while($row = mysqli_fetch_array($db_res)) { // get the DB domainnames entrys
if (empty($row['status'])) {
$items[] = $row['domainnames'];
foreach ($items AS $domain) {
if ( gethostbyname($domain) != $domain ) {
do somthing.....
}
}
}
}
看起来,当while循环迭代时,它使用上一次迭代中的$items-这将浪费时间-因此请尝试此版本(将foreach放入if:
while($row = mysqli_fetch_array($db_res)) { // get the DB domainnames entrys
if (empty($row['status'])) {
$items[] = $row['domainnames'];
foreach ($items AS $domain) {
if ( gethostbyname($domain) != $domain ) {
do somthing.....
}
}
}
}
你的foreach()
循环在while()
循环中是个坏主意。想想看。
在迭代结果集时,$items
不断膨胀——这意味着foreach()
必须工作越来越长
最后,如果您需要为脚本中的下一个任务处理gethostbyname()
值,那么您应该在第一次将条目插入表的同时存储该值——也许新列可以是host
智能货币不会调用gethostbyname()
100000次;当您选择它时,请准备好该值
除了上述逻辑之外,我不认为需要用单个元素/字符串声明数组,然后对其进行迭代 事实上,您的查询应该包含WHERE子句,该子句排除具有
null
/0
/blankstatus
值的行,并包括具有与$domain
匹配的主机(新列)值的行,这样php就不必麻烦任何限定/取消限定条件
foreach ($db_res as $row) { // yes, you can simply iterate the result object
// do whatever with the associative string elements (e.g. $row['domainnames'])
// ...you know this is a string and not an array, right? -^^^^^^^^^^^^^^^^^^^
}
你的foreach()
循环在while()
循环中是个坏主意。想想看。
在迭代结果集时,$items
不断膨胀——这意味着foreach()
必须工作越来越长
最后,如果您需要为脚本中的下一个任务处理gethostbyname()
值,那么您应该在第一次将条目插入表的同时存储该值——也许新列可以是host
智能货币不会调用gethostbyname()
100000次;当您选择它时,请准备好该值
除了上述逻辑之外,我不认为需要用单个元素/字符串声明数组,然后对其进行迭代
事实上,您的查询应该包含WHERE子句,该子句排除具有null
/0
/blankstatus
值的行,并包括具有与$domain
匹配的主机(新列)值的行,这样php就不必麻烦任何限定/取消限定条件
foreach ($db_res as $row) { // yes, you can simply iterate the result object
// do whatever with the associative string elements (e.g. $row['domainnames'])
// ...you know this is a string and not an array, right? -^^^^^^^^^^^^^^^^^^^
}
谢谢你的回答。
在您的帮助下,我能够将程序简化为:
while($row = mysqli_fetch_array($db_res))
{
$domain = $row['domainnames'];
if ( gethostbyname($domain) != $domain ) {
do somthing.....;
}
else{
do somthing.....;
}
}
感觉有点快,但还不够。
@我现在只捕获空的“状态”字段:
谢谢你的回答。
在您的帮助下,我能够将程序简化为:
while($row = mysqli_fetch_array($db_res))
{
$domain = $row['domainnames'];
if ( gethostbyname($domain) != $domain ) {
do somthing.....;
}
else{
do somthing.....;
}
}
感觉有点快,但还不够。
@我现在只捕获空的“状态”字段: