首先,让我们创建一个批处理文件来切换 xDebug。我们假设我们正在运行安装了 Linux Bash shell 的 Windows 10。让我们在位于 Windows PATH 的某个文件夹中创建两个文件:xdebug.bat 和 xdebug.sh。
xdebug.bat:
@echo off
bash xdebug.sh %*
xdebug.sh:
#!/bin/bash
#set -v
ini_file="/mnt/c/laragon/bin/php/php-7.2.10/php.ini"
if [ -z $1 ]
then
if grep -q '^extension=blackfire' "$ini_file"
then
echo 'xdebug is BLACKFIRE'
exit 0
fi
if grep -q '\;zend_extension' "$ini_file"
then
echo 'xdebug is OFF'
exit 0
fi
if grep -q 'xdebug.profiler_enable=0' "$ini_file"
then
echo 'xdebug is ON'
exit 0
else
echo 'xdebug is PROFILER'
exit 0
fi
fi
if [ 'on' = $1 ]
then
sed -i s/^\;zend_extension=php_xdebug/zend_extension=php_xdebug/g $ini_file
sed -i s/^xdebug.profiler_enable=1/xdebug.profiler_enable=0/g $ini_file
sed -i s/^extension=blackfire/\;extension=blackfire/g $ini_file
pid=$(pgrep blackfire-agent)
if [ ! -z $pid ]
then
kill $pid
fi
/mnt/c/laragon/laragon.exe reload apache
exit 0
fi
if [ 'profiler' = $1 ]
then
sed -i s/^\;zend_extension=php_xdebug/zend_extension=php_xdebug/g $ini_file
sed -i s/^xdebug.profiler_enable=0/xdebug.profiler_enable=1/g $ini_file
sed -i s/^extension=blackfire/\;extension=blackfire/g $ini_file
pid=$(pgrep blackfire-agent)
if [ ! -z $pid ]
then
kill $pid
fi
/mnt/c/laragon/laragon.exe reload apache
exit 0
fi
if [ 'off' = $1 ]
then
sed -i s/^zend_extension=php_xdebug/\;zend_extension=php_xdebug/g $ini_file
sed -i s/^xdebug.profiler_enable=1/xdebug.profiler_enable=0/g $ini_file
sed -i s/^extension=blackfire/\;extension=blackfire/g $ini_file
pid=$(pgrep blackfire-agent)
if [ ! -z $pid ]
then
kill $pid
fi
/mnt/c/laragon/laragon.exe reload apache
exit 0
fi
if [ 'blackfire' = $1 ]
then
sed -i s/^zend_extension=php_xdebug/\;zend_extension=php_xdebug/g $ini_file
sed -i s/^xdebug.profiler_enable=1/xdebug.profiler_enable=0/g $ini_file
sed -i s/^\;extension=blackfire/extension=blackfire/g $ini_file
/mnt/c/laragon/laragon.exe reload apache
pid=$(pgrep blackfire-agent)
if [ ! -z $pid ]
then
kill $pid
fi
exec /mnt/c/Programs/Blackfire/blackfire-agent.exe
exit 0
fi
echo 'argument can be "on", "off", "profiler" or "blackfire" only'
exit 1
[blackfire]
;extension=blackfire
; On Windows use the following configuration:
; extension=php_blackfire.dll
; Sets the socket where the agent is listening.
; Possible value can be a unix socket or a TCP address.
; Defaults to unix:///var/run/blackfire/agent.sock on Linux,
; unix:///usr/local/var/run/blackfire-agent.sock on MacOSX,
; and to tcp://127.0.0.1:8307 on Windows.
;blackfire.agent_socket = unix:///var/run/blackfire/agent.sock
blackfire.agent_socket = tcp://127.0.0.1:8308
blackfire.agent_timeout = 0.25
; Log verbosity level (4: debug, 3: info, 2: warning, 1: error)
blackfire.log_level = 4
; Log file (STDERR by default)
blackfire.log_file = /tmp/blackfire.log
; Sets fine-grained configuration for Probe.
; This should be left blank in most cases. For most installs,
; the server credentials should only be set in the agent.
blackfire.server_id = your-server-id
; Sets fine-grained configuration for Probe.
; This should be left blank in most cases. For most installs,
; the server credentials should only be set in the agent.
blackfire.server_token = your-token
[Xdebug]
;zend_extension=php_xdebug-2.6.1-7.2-vc15-nts-x86_64.dll
xdebug.remote_enable=1
xdebug.remote_connect_back=On
xdebug.remote_port="9001"
xdebug.profiler_enable=0
xdebug.profiler_output_dir = c:\laragon\tmp
xdebug.profiler_output_name = %R_%t_cachegrind.out
xdebug.show_mem_delta = 0
xDebug 是一个很棒的调试器,但它会显着降低网站速度。在开发过程中,最好仅在您真正需要时启用 xDebug。让我们看看如何在 Laragon 开发环境中启用、禁用 xDebug 和设置分析模式。我们还将看到如何将这些操作按钮添加到 phpStorm 工具栏。
这就是最终结果的样子(右侧有 4 个极端按钮)。
首先,让我们创建一个批处理文件来切换 xDebug。我们假设我们正在运行安装了 Linux Bash shell 的 Windows 10。让我们在位于 Windows PATH 的某个文件夹中创建两个文件:xdebug.bat 和 xdebug.sh。
xdebug.bat:
xdebug.sh:
用法:
xdebug.bat 调用 xdebug.sh 来执行以下操作:
php.ini(其位置在 xdebug.sh 的第一行中指定)应包含如下行:
如果您不需要此分析器,则可以省略 [blackfire] 部分。
从现在开始,您可以在 PhpStorm 终端中使用 xdebug 命令。但让我们更进一步。我们可以将这些命令添加到 PhpStorm 中的外部工具中。打开设置(Ctrl+Alt+S),找到工具>外部工具,添加一些工具,如下图:
保存您的设置。现在,新命令在 PhpStorm 工具 > 外部工具菜单中可用,是时候向 PhpStorm 工具栏添加按钮了。打开设置(Ctrl+Alt+S),找到Appearance & Behavior > Menus and Toolbars,添加一些按钮,如下图:
您还可以添加按钮图标(.png,16 x 16)。我的图标在这里:
就这样。只需单击相应的按钮即可在 PhpStorm 中轻松地在调试和分析之间切换。