xhprof早就弃坑停止更新了.
其实xdebug除了是一个调试器debugger,还是一个分析器profiler:
;https://pecl.php.net/package/xdebug
zend_extension= "/path/to/xdebug.so"
xdebug.remote_enable = On
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9001
xdebug.remote_log = "/path/to/xdebug.log"
;可以只开分析器profiler(区别于调试器debugger)
xdebug.profiler_enable = On
xdebug.profiler_output_dir = "/path/to/xdebug"
;http://xdebug.org/docs/all_settings#max_nesting_level
;bench.php: Fatal error: Maximum function nesting level of '256' reached, aborting!
;xdebug.max_nesting_level = 1000000
xdebug.cli_color=1
;内存分析
xdebug.auto_trace = 1
xdebug.trace_output_dir = "/path/to/xdebug"
xdebug.trace_format = 0
xdebug.show_mem_delta = 1
xdebug.collect_params = 4
xdebug.collect_return = 1
;命令行高亮
xdebug.cli_color = 1
xdebug.profiler输出的信息cachegrind.out使用kcachegrind查看也可以看到PHP函数调用关系和耗时.
另外,PHP-FPM也提供了一个slowlog慢日志功能,超过request_slowlog_timeout配置的函数会被记录下来.
php-fpm.conf:
slowlog = /path/to/slow.log
request_slowlog_timeout = 1
当一个请求耗时超过1秒后,就会将对应的PHP调用堆栈信息(文件/函数)完整写入到慢日志中.
slow.log:
[10-Mar-2016 11:07:33] [pool www] pid 11618
script_filename = /path/to/your.php
[0x00007fdd62f29260] shell_exec() /path/to/your.php:2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…