Make a test platform for their xhprof

1. First, install php development environment, such as lnmp.

2. Install xhprof

ps:
Remember to download (from github above https://github.com/phacility/xhprof ),
do not pecl.php.net downloaded from the site, it may not support high version (for example, I used php5.4).

installation steps:

1. Unzip the file unzip

2.cd extension

3./usr/local/php/bin/phpize

4./configure --with-php-config=/usr/local/php/bin/php-config --enable-xhprof

5.make

6.make install

7.cd /usr/local/php/etc

8.vim php.ini in add

[xhprof]
extension=xhprof.so
xhprof.output_dir="/www/xhprof/tmp"  //注意创建此目录 

After the restart lnmp, view the phpinfo output. View information related to xhprof which represents success.

Or the command line, type:

php -m |grep xhprof

If the xhprof is success:

** If you are a key installation package of lnmp environment, you can use the following command, otherwise find themselves catalog restart nginx, php **

Restart nginx: nginx -s reload

Restart phpfpm: /etc/init.d/php-fpm restart

3. set up a site

The code in the / www / xhprof directory, just copy the download to install the package xhprof_html XHProf xhprof_lib2 and directories.

Create the test php file (see Code xhprof_html / test.php)

4. Installation extended to support graphical

  • yum update
  • yum -y install dot*
  • yum install graphviz

5. Modify profile php.ini

  • The disable_functions in proc_open deleted.
  • Modify Parameters: auto_prepend_file = / www / xhprof / xhprof_html / header.php
  • Modify Parameters: auto_append_file = / www / xhprof / xhprof_html / footer.php
  • Optional modifying parameters open_basedir: open_basedir = / www / xhprof

ps:

open_basedir: The PHP can open files in the specified directory tree limit

Restriction specified with open_basedir is actually a prefix, not a directory name.

That "open_basedir = / dir / incl" also allows access to "/ dir / include" and "/ dir / incls", if they exist.

If you want to restrict access to only the specified directory, end with a slash name. For example: "open_basedir = / dir / incl /".

6. At this point all sites can produce xphrof information under the server.

【header.php】

if (extension_loaded('xhprof')) {
     include_once '/www/xhprof/xhprof_lib/utils/xhprof_lib.php';
     include_once '/www/xhprof/xhprof_lib/utils/xhprof_runs.php';
 xhprof_enable(XHPROF_FLAGS_CPU && XHPROF_FLAGS_MEMORY); //为测试test.php里使用这行
 //xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY); //线上可以使用这个
}

ps:

XHPROF_FLAGS_NO_BUILTINS (integer)

Skip all such built-in (internal) function.

XHPROF_FLAGS_CPU (integer)

Performance data output from the CPU to add the data.

XHPROF_FLAGS_MEMORY (integer)

Performance data output from the memory data is added.

【footer.php】

if (extension_loaded('xhprof')) {
    $profiler_namespace = 'xhprof_foo';
    $xhprof_data = xhprof_disable();
    $xhprof_runs = new XHProfRuns_Default();
    $run_id = $xhprof_runs->save_run($xhprof_data, $profiler_namespace);
    echo ""."Table View" . "";
    echo "    ";
    echo ""."Photo View" . "";
}

【test.php】

Simple test code

//要测试的代码 开始
for($i=0;$i<10000;$i++){
    strtoupper(substr(md5(md5(mt_rand())),1,20));
    echo $i.'
';
}
//结束测试代码

Guess you like

Origin www.cnblogs.com/luyuqiang/p/xhprof.html