打开 PHP xdebug 的快捷方式

Shortcut to turn PHP xdebug ON

打开 xdebug 的脚本有效,但我无法想出创建 运行 它的快捷方式。如果我在 C:\Users\George\Desktop\Development\Config Files 中打开管理员 PowerShell,命令 .\PHPxDebugOn 将使用修改后的 php.ini 重新启动 Apache。 (还有一个 PHPxDebugOff。ps1 关闭 xdebug。)单击快捷方式(运行 作为管理员打开)只会闪烁黑屏,但 Apache 没有变化。

脚本:

$iniFile = "C:\Users\George\Desktop\Development\Config Files\php.ini"
$xFile = "C:\Users\George\Desktop\Development\Config Files\xdebug.ini"
$phpIniFile = "C:\PHP\php.ini"

get-content $iniFile, $xFile | set-content $phpIniFile

C:\Apache24\bin\httpd -k restart

快捷方式目标:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -file "&C:\Users\George\Desktop\Development\Config Files\PHPxDebugOn.ps1"

问题出在快捷方式目标上。

如果路径正确,删除 & 符号应该可以解析脚本而不是 运行ning。

如果快捷方式中的目标文件以任何方式无效,PowerShell 将退出而不尝试 运行 脚本。除非命令中的所有内容都可以是 evaluated/parsed/retrieved,否则默认行为是停止所有内容并报告错误。这解释了为什么 window 消失了,即使指定了 -NoExit 参数。 PowerShell 确实会在 window 可见的短暂时刻显示错误。屏幕刷新率和处理器速度是它们的现状,屏幕截图有点难以捕捉。

示例 1:%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file "&C:\scripts\hello.ps1"

示例 2:%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file "C:\scripts\hello.ps2"

示例 3(成功):%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -file "C:\scripts\hello.ps1"

备注:

  • 重现环境:Windows 7 Enterprise with Powershell 5.0 2015 年 4 月预览版
  • .ps2 文件扩展名在某些系统上可能有效
  • 您可以使用 -NoProfile 参数跳过加载 PowerShell 配置文件
  • File must be the last parameter in the command,因为在 File 参数名称之后键入的所有字符都被解释为脚本文件路径后跟脚本参数

鉴于我的评论是,根据 OP,这是解决问题的更好方法,我将 post 在这里作为答案:

我要做的是创建第二个指向同一源的虚拟主机,但加载单独的 php.ini 文件以在该虚拟主机上启用 xdebug。这样,您可以简单地使用 http://local.project.devhttp://local.project.debug 到 运行 启用 xdebug 的相同代码。这样,您不必每次想使用 xdebug 单步执行代码时都重新启动 apache。