本文介绍了如何找出当前正在运行的PHP可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从PHP程序内部,我想知道执行它的二进制文件的位置.为此,Perl具有$^X
.在PHP中是否有等同功能?
From inside a PHP program I want to know the location of the binary executing it. Perl has $^X
for this purpose. Is there an equivalent in PHP?
因此,它可以使用自身执行子PHP进程(而不是硬编码路径或假定"php"正确).
This is so it can execute a child PHP process using itself (rather than hard code a path or assume "php" is correct).
更新
- 我正在使用lighttpd + FastCGI,而不是Apache + mod_php.是的,有一个PHP二进制文件.
- eval/include不是解决方案,因为我正在生成一个服务器,该服务器必须在请求之后才能运行.
我尝试过但不起作用的事情:
-
$_SERVER['_']
看起来像我在命令行中想要的,但实际上是从上次执行程序的外壳设置的环境变量中获取的.从Web服务器运行时,这是Web服务器二进制文件. -
which php
将不起作用,因为不能保证PHP二进制文件与Web服务器的PATH
中的二进制文件相同.
$_SERVER['_']
looks like what I want from the command line but its actually from an environment variable set by the shell of the last executed program. When run from a web server this is the web server binary.which php
will not work because the PHP binary is not guaranteed to be the same one as is in the web server'sPATH
.
谢谢.
推荐答案
PHP_BINDIR常量为您提供php二进制文件所在的目录
The PHP_BINDIR constant gives you the directory where the php binary is
这篇关于如何找出当前正在运行的PHP可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!