Profiling PHP running in apache

后端 未结 4 1734
迷失自我
迷失自我 2020-12-21 23:27

I want to know what functions are being called and what time each request is taking for an application which is running on apache.

Is there any tool or any other way

相关标签:
4条回答
  • 2020-12-21 23:52

    Xdebug can write a profiling file that you can analyze in kcachegrind or wincachegrind.

    0 讨论(0)
  • 2020-12-22 00:00

    It depends on whether you want active or passive profiling.

    Passive tools such as New Relic work silently in the background and collect a little information about all requests by sacrificing a small amount of compute resources. These generally have more information regarding the entire server stack. These are typically used for production environments, which sounds like what you require.

    Active profilers are used for development and will run just once per request, collecting a lot of information specifically about the part of the application you are working on at the cost of a large performance hit. The most common PHP active profiler is probably Xdebug.

    Ways to analyse the data from Xdebug:

    NOTE: If you use a virtual machine, vagrant, docker etc make sure you set the output dir to a shared volume, accessible outside of the virtual machine

    e.g.

    (php.ini) xdebug.profiler_output_dir = "/project_root/tmp"

    If you use PHPStorm:

    • Tools > Analyse Xdebug Profiler snapshot...

    For those using Xdebug on MacOS:

    Using homebrew install qcachegrind and AppViz

    • brew install qcachegrind

    • brew install graphviz

    Then run it from command line:

    qcachegrind cachegrind.out.1394

    OR just run qcachegrind and open the cachegrind file generated by xdebug using the GUI navigator

    0 讨论(0)
  • 2020-12-22 00:03

    One of the most used industry tools for this is: http://www.xdebug.org/

    I have used it religiously for a long time now! From it's front-page it does the following:

    "The Xdebug extension helps you debugging your script by providing a lot of valuable debug information. The debug information that Xdebug can provide includes the following:

    * stack traces and function traces in error messages with:
          o full parameter display for user defined functions
          o function name, file name and line indications
          o support for member functions
    * memory allocation
    * protection for infinite recursions"
    
    0 讨论(0)
  • 2020-12-22 00:11

    There are couple of PHP profiling tools,
    such as

    • xdebug
    • Particletree
    0 讨论(0)
提交回复
热议问题