PECL(http://pecl.php.net/package/xhprof)上提供的最新扩展并不支持php7版本。

如果想为php7使用xhprof进行性能分析的话请参考https://github.com/Yaoguais/phpng-xhprof所介绍的方法进行编译安装。

Installation

git clone git@github.com:Yaoguais/phpng-xhprof.git ./xhprof
cd xhprof
phpize
./configure
make clean && make && make test && sudo make install

Then add the configuration into php.ini

[xhprof]
extension = phpng_xhprof.so
xhprof.output_dir = /tmp/xhprof

If you compiled PHP7 from source code, then

git clone git@github.com:Yaoguais/phpng-xhprof.git ./xhprof
cd xhprof
/path/to/php7/bin/phpize
./configure --with-php-config=/path/to/php7/bin/php-config
make clean && make && make test && sudo make install

Then add the profile code

xhprof_enable();
// your code
// ...
file_put_contents((ini_get('xhprof.output_dir') ? : '/tmp') . '/' . uniqid() . '.xhprof.xhprof', serialize(xhprof_disable()));

Test

There are 12 test cases, the extension by 11,and the rest can not be due to the result of the PHP core,which is call_user_function family of functions.

You can use "make test" command to test the extension,and there are also simple test examples.

/path/to/php7/bin/php diff/enable.php
ls -l diff

Notice

This extension replaces the PHP core, so when you use other extensions like xdebug or phpdbg,which might be impaired.

You should add the phpng-xhprof configuration options to the php.ini of the bottom,and this is due to PHP 's startup sequence resulting from extension.



Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐