HOW TO INSTALL XHPROF FOR PROFILING PHP YII 1.X APPLICATION

  1. Introduction
    In software engineering, profiling is a technique used to analyze applications at run-time, in order to identify possible bottlenecks and performance issues within an application. It is an essential resource for software optimization. Profiling differs from benchmarking because it analyzes the application at code level, while benchmarking is intended to analyze the overall application performance as experienced by the end user.

    A profiler is a software that will gather detailed information about the application in order to generate statistics and insightful data about memory usage, frequency and duration of function calls, time to respond to a request, amongst other things.XHProf is a profiler designed to analyze PHP applications. Created and open sourced by Facebook, XHProf works as a passive profiler, which means it will work in the background while having minimum impact on the application’s performance, making it suitable to be used on production environments.
    (copy from digital ocean)

  2. How to install xhprof
    Update the package manager cache with

    sudo apt-get update

    Next, we’ll install pecl with the php-pear package. We’ll also need php5-dev in order to install PHP modules via pecl
    sudo apt-get install php-pear php5-dev

    Install xhprof via pecl

    sudo pecl install xhprof-beta

    Edit php.ini file to enable your xhprof extension. Look like the below,
    Pasted_Image_11_15_16__6_13_PM.png
    Restart your php daemon, open your phpinfo to make sure xhprof extension is loaded properly,
    Pasted_Image_11_15_16__6_17_PM.png

  3. How to configure in Yii 1.x application
    Download Yii-xhprof and put into protected/extensions, you will see something like below,
    Pasted_Image_11_15_16__6_28_PM.png
    Make sure this config is in your application configuration,

    'preload' => array(
     'xhprof'
     ),

    and

     'components' => array(
        'xhprof' => array(
            'class' => 'ext.yii-xhprof.XHProfComponent',
            'libPath' => '/full/path/to/xhprof_lib',
            'htmlReportBaseUrl' => 'http://url.path.to/xhprof_html',
     ),),
  4. How to view the result
    Download PHP view and library package here, extract and copy these into your proper place, mine is in the root of application,
    Pasted_Image_11_15_16__10_07_PM.png
    In the xhprof configuration above, configure the libPath point to xhprof_lib folder
    Add virtual host point to xhprof_html in order to view the result. You can use apache or nginx,
    Yah, all will be done, you should see something like this
    Pasted_Image_11_15_16__10_20_PM.png
    You can click on Report link to see all the calls
  5. How to generate callgraph
    Click on Callgraph for visualization view, you can see all methods’ calls graphically like below
    Pasted_Image_11_16_16__9_28_PM.png
    Make sure graphziz is installed on your system, if not you may encounter this problem

    failed to execute cmd: " dot -Tpng". stderr: `sh: 1: dot: not found '

    Install graphziz as the command below

    sudo apt-get install graphviz
HOW TO INSTALL XHPROF FOR PROFILING PHP YII 1.X APPLICATION