如何在没有外壳访问的情况下获取php解释器/二进制文件的完整路径 [英] How to get the full path to php interpreter / binary without shell access

查看:105
本文介绍了如何在没有外壳访问的情况下获取php解释器/二进制文件的完整路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从php脚本获取完整的php解释器路径(无命令行访问).

我需要做的是:

$foo = "/usr/bin/php";
echo $foo;

但是我需要先获取路径,以便可以将其分配给foo.

如果您有一个可以在Windows和nix上都更好的解决方案,但如果不能,则nix会很好.

在您问之前,

  1. 问主持人是不可能的
  2. 无外壳访问权限

问题是,使用其输出的任何内容均无效.例如,PHP_BINDIR将输出/usr/bin,但使用/usr/bin/php将无济于事.完整的代码是:

exec("php-cli $path_to_file > /dev/null 2>/dev/null &"); 

但是即使使用/usr/bin/php-cli,即使它告诉了我,它也不起作用.我必须使用:

exec("/opt/php52/bin/php-cli $path_to_file > /dev/null 2>/dev/null &");

例如,对于此特定主机.

解决方案

您可以使用以下常量找到PHP二进制路径:

PHP_BINDIR

从PHP 5.4开始,您可以使用以下常量获取当前正在实际运行的可执行文件的路径:

PHP_BINARY

http://php.net/manual/en/reserved.constants.php

How can I get the full path to php interpreter from a php script (no command line access).

What I need to do is:

$foo = "/usr/bin/php";
echo $foo;

But I need to get the path first so I can assign it to foo.

If you have a solution that works on both Windows and nix even better but if not, nix would be fine.

Before you ask,

  1. Asking the host is out of the question
  2. No shell access

The problem is that using whatever it outputs doesn't work. For example PHP_BINDIR will output /usr/bin but using /usr/bin/php won't help. The full code is:

exec("php-cli $path_to_file > /dev/null 2>/dev/null &"); 

But even using the /usr/bin/php-cli doesn’t work even though it tells me that. I have to use:

exec("/opt/php52/bin/php-cli $path_to_file > /dev/null 2>/dev/null &");

For this particular host for example.

解决方案

You can find the PHP binary path with this constant:

PHP_BINDIR

As of PHP 5.4, you can get the path to the executable actually running currently with this constant:

PHP_BINARY

http://php.net/manual/en/reserved.constants.php

这篇关于如何在没有外壳访问的情况下获取php解释器/二进制文件的完整路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆