如何显示PHP搜索引擎执行结果前的时间和结果数


how to display php search engine execution time and number of results before the results

好的,所以我建立了一个PHP搜索引擎,它工作得很好,但是有些人对我说它很慢。

在他们的机器上输出HTML结果表时可能会显得很慢,但我知道它运行得非常快。

所以我决定做一个花哨的功能,就像许多搜索引擎,如谷歌有一个说"你的搜索返回X结果在Y时间"作为一种方式告诉人们,可能不是我的搜索引擎的错误,他们花了很长时间才看到他们的查询结果。

我做了一个功能,几乎证实了我已经知道的,那就是搜索引擎很快。

问题是结果在计时器/resultcounter之前被回应,因为它要计算结果,它已经有了结果,并且要显示它找到它们所花费的时间,显然搜索引擎必须完成运行。

我使用html+css+php为这个项目,我不想不得不使用javascript,我应该如何显示定时器/结果计数器之前的实际结果?

您可以使用time代码运行search查询,然后在搜索完成后返回time代码。

$start = microtime(true);
$searchdata = //Search Functions    
$end = microtime(true);
$time = ($end - $start);
echo $time."".$searchdata
<?PHP
$print=null;
$start=microtime(); 
echo 'etc etc you just found the results<br><br>'; 
$print= '<br><br>It took '. number_format(microtime()-$start,12).' seconds to find the results.<br><br>';
echo 'etc etc do what else is to be done, end of script<br>';
echo '__________________________________________________________<br><br>';
echo $print,'It took ', number_format(microtime()-$start,12),' seconds in total.'; 
?>
    $start_time = microtime(true);    
    .
    .
     //Search Logic
    .
    .
    $end_time = microtime(true);
    $time = ($end_time - $start_time);
    echo "Search Time : ".$time." sec't";