Often times when I see PHP that is meant to be ran from the command line, it will have this line #!/usr/bin/env php
at the top of the file like this...
通常,当我看到要从命令行运行的PHP时,它会有这一行#!/usr/bin/env php在文件的顶部,像这样…
#!/usr/bin/env php
<?php
// code
?>
I was wanting to know if this is meant just for when the file is ran on a Linux/Unix system or is needed for running on Windows as well?
我想知道这是否只适用于在Linux/Unix系统上运行的文件,还是也适用于在Windows上运行的文件?
2 个解决方案
#1
23
The "hashbang" line is required for auto-detection of the type of script. It enables this sort of usage:
“hashbang”行用于自动检测脚本的类型。它使这种用法成为可能:
[pfisher ~]$ chmod +x run-me.php
[pfisher ~]$ run-me.php
That line is not needed if you pass the filename as an argument to the php interpreter, like so:
如果将文件名作为参数传递给php解释器,则不需要这一行,如下所示:
[pfisher ~]$ php run-me.php
#2
1
No it's not, you can directly use
不,你可以直接使用。
#!/path/to/php
Running php (or anything else) through the env utility is a weak security measure. Dpending on the platform, will "fix" PATH, LIB, and other environment variables according to various config files and potentially remove some of the dangerous values in there (e.g. env on HPUX).
通过env实用程序运行php(或其他任何东西)是一种弱安全性度量。Dpending on平台上,将根据各种配置文件“修复”路径、LIB和其他环境变量,并可能删除其中的一些危险值(例如HPUX上的env)。
It is also to limit the scope of shell-expansions on certain environments. (See man 1 env on Linux).
它还限制了在某些环境中扩展shell的范围。(参见Linux上的man 1 env)。
#1
23
The "hashbang" line is required for auto-detection of the type of script. It enables this sort of usage:
“hashbang”行用于自动检测脚本的类型。它使这种用法成为可能:
[pfisher ~]$ chmod +x run-me.php
[pfisher ~]$ run-me.php
That line is not needed if you pass the filename as an argument to the php interpreter, like so:
如果将文件名作为参数传递给php解释器,则不需要这一行,如下所示:
[pfisher ~]$ php run-me.php
#2
1
No it's not, you can directly use
不,你可以直接使用。
#!/path/to/php
Running php (or anything else) through the env utility is a weak security measure. Dpending on the platform, will "fix" PATH, LIB, and other environment variables according to various config files and potentially remove some of the dangerous values in there (e.g. env on HPUX).
通过env实用程序运行php(或其他任何东西)是一种弱安全性度量。Dpending on平台上,将根据各种配置文件“修复”路径、LIB和其他环境变量,并可能删除其中的一些危险值(例如HPUX上的env)。
It is also to limit the scope of shell-expansions on certain environments. (See man 1 env on Linux).
它还限制了在某些环境中扩展shell的范围。(参见Linux上的man 1 env)。