PHP 命令行脚本 Windows Start In 参数

PHP command line script Windows Start In parameter

当 运行 在 Windows 中从命令行运行脚本时,Start in 参数是否设置脚本中的 $_SERVER['DOCUMENT_ROOT']?

根据php.net文档,答案不是。:

The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here

http://php.net/manual/en/reserved.variables.server.php

我从一些有帮助的评论者那里发现 Start In 设置了 CWD(当前工作目录)并且在使用 CLI 时没有 $_SERVER 数组,除非你专门添加一个开关为了它。

要在脚本中获取 CWD 的值,请使用内置函数:getcwd()

在我的例子中,我试图包含一个与脚本相关的文件,并错误地认为我需要使用它的完整系统路径。但最终,相对路径代替了完整的系统路径起作用了。