编程获取路径到PHP [英] Programmatically get path to php
问题描述
我想要做的比类似的事情<一href=\"http://stackoverflow.com/questions/1540565/how-to-fork-a-video-conversion-process-into-background-in-php\">How到&QUOT;叉&QUOT;视频转换过程分为背景,在PHP :
I'd like to do a similar thing than How to "fork" a video conversion process into background, in php? :
exec("/usr/bin/php ./foo.php > /dev/null 2>&1 &"); // executed in Apache
不过,这会在各种平台上运行:我的机器,其中PHP是编译〜/,窗,几督促服务器...
However, this will run on a variety of platforms : my machine, where php is compiled in ~/, windows, several prod servers...
有没有一种方法以编程方式获得的/ usr / bin中/ PHP的一部分?
Is there a way to programmatically get the "/usr/bin/php" part ?
东西我能想到的:
- 获取当前的PID,想从中可执行
- 在C,第一个参数是可执行文件路径,也许有类似的东西
推荐答案
最简单的方法是简单地确保 PHP
CLI二进制文件在发现$ PATH
环境变量,然后只使用 PHP /path/to/foo.php
。
Easiest way is to simply make sure the php
CLI binary is found in $PATH
environment variable, and then just use php /path/to/foo.php
.
在UNIX上,您也可以使用的/ usr / bin中/ env的PHP
将执行第一个找到的 PHP
二进制在 $ PATH
。但是,这显然不会在Windows中工作。
On UNIX you can also use /usr/bin/env php
which will execute the first php
binary found in $PATH
. But that obviously won't work in Windows.
最后一个明显的方法是有位置 PHP
作为一个配置选项,并在适当的时候使用用户指定的路径。
Lastly one obvious way is to have the location to PHP
as a configurable option, and use the user-specified path when appropriate.
这篇关于编程获取路径到PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!