PHP Windows 上的开发服务器无法读取环境变量

PHP development server on Windows fails to read environment variables

我是运行PHP通过命令行如下:

C:\PHP.6.4\php.exe -S localhost:8080 -t "C:\path\to\dir"

之前创建了一个环境变量,APPLICATION_ENV。尝试在 PowerShell 中查看它会给我:

PS C:\Users\Eyas> $env:APPLICATION_ENV
development

然而,当我通过 print_r 查看 $_ENV$_SERVER 时,我得到的只是:

# $_ENV
Array
(
[ALLUSERSPROFILE] => [...]
[APPDATA] => [...]
...
[COMPUTERNAME] => [...]
[ComSpec] => C:\WINDOWS\system32\cmd.exe
...
[HOME] => [...]
[HOMEDRIVE] => [...]
[HOMEPATH] => [...]
[LOCALAPPDATA] => [...]
...
[Path] => [...]
...
[ProgramData] => C:\ProgramData
[ProgramFiles] => C:\Program Files (x86)
[ProgramFiles(x86)] => C:\Program Files (x86)
[ProgramW6432] => C:\Program Files
[PSModulePath] => C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
[PUBLIC] => C:\Users\Public
[SESSIONNAME] => Console
[SystemDrive] => C:
[SystemRoot] => C:\WINDOWS
[TEMP] => [...]
[TMP] => [...]
[USERDOMAIN] => [...]
[USERDOMAIN_ROAMINGPROFILE] => [...]
[USERNAME] => [...]
[USERPROFILE] => [...]
[VS110COMNTOOLS] => C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
[VS120COMNTOOLS] => C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
[windir] => C:\WINDOWS
[__COMPAT_LAYER] => DetectorsWin7
)

# $_SERVER
Array
(
[DOCUMENT_ROOT] => [...]
[REMOTE_ADDR] => ::1
[REMOTE_PORT] => 44786
[SERVER_SOFTWARE] => PHP 5.6.4 Development Server
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_NAME] => localhost
[SERVER_PORT] => 8080
[REQUEST_URI] => [...]
[REQUEST_METHOD] => GET
[SCRIPT_NAME] => [...]
[SCRIPT_FILENAME] => [...]
[PHP_SELF] => [...]
[HTTP_HOST] => localhost:8080
[HTTP_CONNECTION] => keep-alive
[HTTP_CACHE_CONTROL] => max-age=0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
[HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,ar;q=0.6,de;q=0.4
[HTTP_COOKIE] => _ga=GA1.1.750333862.1419043051
[REQUEST_TIME_FLOAT] => 1421118347.0132
[REQUEST_TIME] => 1421118347
[argv] => Array
    (
    )

[argc] => 0
)

此外,getenv("APPLICATION_ENV") returns 一个空结果。

可能是什么问题?

看起来我正在重新启动 php.exe 并从我在更改环境变量后尚未重新启动的进程中重新启动它。因此,在启动进程时,php.exe 获取了其父(生成)进程的环境,并没有重新加载环境变量。

在我的例子中,我使用的是 PhpStorm,重新启动后我可以看到我的新环境变量。