为什么我的PHP脚本花费太多时间?

时间:2014-04-09 09:00:27

标签: php parsing http-authentication

我不知道我做错了什么。该脚本需要大约50秒才能执行。我使用simple_html_dom_parser来解析数据库中的URL。解析顺利进行并花费8秒,但其余代码需要花费大量时间。

include('config.php');
include('simple_html_dom.php');
$query_select = "select `nasname`,`username`,`password` from `nas`";
$result_select = mysql_query($query_select);
$web_parser = array();
while($row = mysql_fetch_array($result_select))
{  
   $host = $row['nasname'];
   $port = '5006';
   $url='http://'.$row['nasname'].':5006/';
   $username = $row['username'];
   $password = $row['password'];
   $waitTimeoutInSeconds = 1; 
 if($fp = fsockopen($host,$port,$waitTimeoutInSeconds)){                    
   $context = stream_context_create(array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$username:$password")
    )
        )); 
$data = file_get_html($url,true,$context);
foreach($data->find('tr') as $row) { 
        $users = $row->find('td',9)->plaintext;
        $web_parser[$users] = $users; 
        echo $users;
   }
$data->clear(); 
unset($data);
}   }

0 个答案:

没有答案