我做的一个web程序运行起来很慢,有没有什么方法可以查处在那步都花了多长时间,以定位为何运行起来这么慢?
望能够详细指导一下。

解决方案 »

  1.   

    不断地添加 echo 1; 2 3 4 5 6 7 ........等等
      

  2.   

    好像有专门的debug工具,百度看看
      

  3.   

    评估一段 PHP 代码的执行时间:<?php
    // A function that records the time when it is called
    function profile($dump = FALSE)
    {
        static $profile;    // Return the times stored in profile, then erase it
        if ($dump) {
            $temp = $profile;
            unset($profile);
            return ($temp);
        }    $profile[] = microtime();
    }// Set up a tick handler
    register_tick_function("profile");// Initialize the function before the declare block
    profile();// Run a block of code, throw a tick every 2nd statement
    declare(ticks=2) {
        for ($x = 1; $x < 50; ++$x) {
            echo similar_text(md5($x), md5($x*$x)), "<br />;";
        }
    }// Display the data stored in the profiler
    print_r(profile (TRUE));
    ?>  
     
    这个例子评估“declare”中的 PHP 代码,每执行两条低级语句就记录一次时间。此信息可以用来找到一段特定代码中速度慢的部分。这个过程也可以用其它方法完成,但用 tick 更方便也更容易实现。 Ticks 很适合用来做调试,以及实现简单的多任务,后台 I/O 和很多其它任务。