简体   繁体   English

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

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

ok so i built a php search engine and it was working beautifully, but some people said to me that it was slow. 好的,所以我建立了一个php搜索引擎,它运行得很漂亮,但是有人对我说它很慢。

maybe it may appear slow on their machines when the thing outputs the results table on html but i know it's running ludicrously fast. 当东西在html上输出结果表时,也许在他们的机器上看起来很慢,但是我知道它的运行速度非常快。

so i decided to make a fancy feature like the one many search engines like google have saying that ''your search returned X results in Y time'' as a way of telling people that probably isn't my search engine fault that they're taking a long time to see the results for their query. 因此,我决定采用像Google这样的许多搜索引擎所说的功能,作为“您的搜索在Y时间返回了X个结果”的一种功能,以告诉人们可能不是我的搜索引擎错误需要很长时间才能查看其查询的结果。

i've made the feature that pretty much confirms what i already know, that is that the search engine is fast. 我所做的功能几乎可以证实我已经知道的功能,那就是搜索引擎速度很快。

the problem is the results are echoed before the timer/resultcounter thing is, because for it to count the results it already has to have the results and for it to display the time it took to find them obviously the search engine had to finish running. 问题在于结果要在计时器/结果计数器之前被回显,因为要对结果进行计数,它必须已经有结果,并且要显示找到它们所需的时间,显然搜索引擎必须完成运行。

i'm using html+css+php for this project and i don't want to have to use javascript, how should i display the timer / results counter before the actual results? 我为此项目使用html + css + php,并且我不想使用javascript,在实际结果之前应如何显示计时器/结果计数器?

You can run the search queries with the time code, then echo them after the search has finished with the time code coming first. 您可以使用time码运行search查询,然后在搜索完成后以time码为第一的方式回显它们。

$start = microtime(true);
$searchdata = //Search Functions    
$end = microtime(true);
$time = ($end - $start);
echo $time."".$searchdata
    $start_time = microtime(true);    
    .
    .
     //Search Logic
    .
    .
    $end_time = microtime(true);
    $time = ($end_time - $start_time);
    echo "Search Time : ".$time." sec\t";
<?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.'; 
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM