【问题标题】:how to display php search engine execution time and number of results before the results如何在结果之前显示php搜索引擎执行时间和结果数
【发布时间】:2017-07-28 18:28:14
【问题描述】:

好的,所以我建立了一个 php 搜索引擎,它运行良好,但有些人对我说它很慢。

当事物在 html 上输出结果表时,可能在他们的机器上看起来很慢,但我知道它的运行速度快得离谱。

所以我决定制作一个奇特的功能,就像谷歌等许多搜索引擎所说的“你的搜索在 Y 时间返回 X 个结果”,以此来告诉人们这可能不是我的搜索引擎的错他们需要很长时间才能看到查询结果。

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

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

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

【问题讨论】:

    标签: php html css search-engine


    【解决方案1】:

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

    $start = microtime(true);
    $searchdata = //Search Functions    
    $end = microtime(true);
    $time = ($end - $start);
    echo $time."".$searchdata
    

    【讨论】:

    • 我没有使用您的建议,但它给了我一个想法,即将所有搜索结果值转换为一个数组,然后在输出找到的结果的时间和数量后将其内爆。我一直在寻找一种解决方案,它只是“重新组合”html/css 页面上的东西而不是这个,但我厌倦了思考并且无处可去,并决定根据你的回答来做这件事。它使搜索引擎的速度比我想的要慢一点,但它仍然快得要命,所以我就这样离开了。谢谢
    • 酷,但我认为它不应该减慢搜索速度,因为您所做的只是安排输出。可能你不应该使用数组。
    • 也许如果我将它转换为字符串而不是它会更快,我会尽可能检查它,但是慢一点是可以理解的,因为该函数将结果直接输出到页面,现在它必须将它们存储在一个数组中以便稍后输出它们。谢谢你的评论
    • 是的。铸造会显着增加它。像$search .= "Search 1" 这样的东西。 . .
    【解决方案2】:
    <?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.'; 
    ?>
    

    【讨论】:

      【解决方案3】:
          $start_time = microtime(true);    
          .
          .
           //Search Logic
          .
          .
          $end_time = microtime(true);
          $time = ($end_time - $start_time);
          echo "Search Time : ".$time." sec\t";
      

      【讨论】:

        猜你喜欢
        • 2014-07-10
        • 2014-07-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-08
        • 1970-01-01
        • 2021-02-23
        相关资源
        最近更新 更多