官方文档 Xdebug: Documentation » Profiling
docker内构建php8+nginx 可参考 docker构建nginx+php8_fangdong88的博客-CSDN博客_docker nginx php
docker 安装 xdebug
- pecl install xdebug
- docker-php-ext-enable xdebug
php --ini 查看php配置路径
修改 docker-php-ext-xdebug.ini 配置文件, 如果无法使用vi命令,安装vim
docker内安装vim
- apt-get update
- apt-get install vim
编辑 docker-php-ext-xdebug.ini
- zend_extension=xdebug
- xdebug.mode=profile
- xdebug.start_with_request=XDEBUG_TRIGGER // 可选,如果不配置这个所有访问都会生成分析文件,启用的话可通过url参数的形式来触发分析,例如 http://localhost/inde.php?XDEBUG_TRIGGER
- xdebug.output_dir=/www // 替换为你docker内与本地目录映射的地址
- xdebug.use_compression=false
重启 docker php
安装xdebug脚本分析软件
- brew install qcachegrind
- 启动命令 qcachegrind
调用api,会在上面设置的 xdebug.output_dir 目录里生成xdebug分析文件,在qcachegrind里打开即可看到分析内容
我本地是php7.2的,之前通过brew install php@7.2 安装的
上面执行完后php无法正常运行了,提示
- dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.68.dylib
- Referenced from: /usr/local/opt/php@7.2/bin/php
- Reason: image not found
- [7] 63371 abort php -m
我猜是安装qcachegrind导致的,解决办法,只有重装php
- brew upgrade php@7.2
- ==> Upgrading 1 outdated package:
- php@7.2 7.2.34_2 -> 7.2.34_4
- Error: php@7.2 has been disabled because it is deprecated upstream!
因为我不想换版本,本来想直接通过升级来解决,但是官方brew又不支持php7.2了,只有想其他办法来重装.
先卸载原来的php
- brew services stop php@7.2
- brew uninstall php@7.2
重装php7.2
- brew tap shivammathur/php
- brew install shivammathur/php/php@7.2
安装成功提示
- The php.ini and php-fpm.ini file can be found in:
- /usr/local/etc/php/7.2/
-
- php@7.2 is keg-only, which means it was not symlinked into /usr/local,
- because this is an alternate version of another formula.
-
- If you need to have php@7.2 first in your PATH, run:
- echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc
- echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
-
- For compilers to find php@7.2 you may need to set:
- export LDFLAGS="-L/usr/local/opt/php@7.2/lib"
- export CPPFLAGS="-I/usr/local/opt/php@7.2/include"
-
-
- To restart shivammathur/php/php@7.2 after an upgrade:
- brew services restart shivammathur/php/php@7.2
- Or, if you don't want/need a background service you can just run:
- /usr/local/opt/php@7.2/sbin/php-fpm --nodaemonize
然后根据上面提示,启动php7.2
brew services start shivammathur/php/php@7.2
惊奇的发现之前安装的php扩展都还在,什么都不用改,很nice.