PHP调用带参PowerShell脚本时浏览器卡顿问题求助
PHP调用带位置参数的PowerShell脚本时进程挂起问题
我正在将SVN仓库迁移至新服务器,现有一个PHP页面用于查看SVN仓库中两个标签的差异。在页面选择项目、起始标签、结束标签及其他选项后点击提交,PowerShell脚本会生成汇总差异的HTML文件并返回文件名。但在新服务器上访问该页面时浏览器卡顿,问题已定位到shell_exec代码行,注释该行后页面可正常加载。
复现问题的测试代码
$proj = "ProjectName"; $btag = "2222Rev40"; $etag = "2222Rev45"; $bas = "Branch2222"; $diffd = "Code"; $buildCmd = "R:\\scripts\\buildlog.ps1 $proj $btag $etag $bas $diffd"; $cmd = "powershell.exe -InputFormat none -ExecutionPolicy unrestricted -NoProfile $buildCmd"; echo shell_exec($cmd);
运行上述代码时浏览器卡顿,任务管理器中可见PowerShell进程启动后无法退出。但将echo shell_exec($cmd);替换为echo $cmd;,复制输出的命令到PowerShell终端可正常执行:
PS C:\Users\username> powershell.exe -InputFormat none -ExecutionPolicy unrestricted -NoProfile R:\scripts\buildlog.ps1 ProjectName 2222Rev40 2222Rev45 Branch2222 Code 20230606140531-ProjectName-2222Rev40-2222Rev45-Buildlog.html PS C:\Users\username>
生成的HTML文件格式符合预期,说明SVN调用本身无问题。
已尝试的排障操作
- 在PowerShell调用中添加
-InputFormat none - 修改PowerShell调用的
-ExecutionPolicy为unrestricted(原使用RemoteSigned) - 在PowerShell调用中添加
-NoProfile - 将x86和x64运行时的默认
ExecutionPolicy更新为unrestricted - 创建可被PHP成功调用的测试PowerShell脚本
注:参考相关问题实现Aaron Jenson的测试方案,PHP可正常调用执行get-process的脚本,但无法调用带位置命令行参数的目标脚本。给测试调用添加无用参数并调整格式后可运行,替换buildlog.ps1为test.ps1时,浏览器可正常显示运行结果。
内容的提问来源于stack exchange,提问作者TehDwArF
相关产品推荐
相关产品推荐

