0

I want to know the path of the php interpreter from within a php script.

Such the result will be /usr/bin/php for example

I want this to work both for windows and unix.

How can I do it?

edit: I need this information in runtime, so parsing the result of phpinfo() is less than ideal solution

shealtiel
  • 8,020
  • 18
  • 50
  • 82

3 Answers3

1

To get all the detailed information about your PHP installation, place a call to phpinfo() in a blank file and it will display what you need.

http://php.net/manual/en/function.phpinfo.php

<?php
    phpinfo();
?>

Just remember to delete the file when you push it to production.

rxgx
  • 5,089
  • 2
  • 35
  • 43
1

From a command line PHP script, try $_SERVER['_']. The location of PHP in a web-based script doesn't really have much meaning, since PHP is embedded into the webserver for the most part, and won't have any executable path.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • I heard this, but not quite understand. Does it mean that php is compiled into servers executable? Otherwise, the server should be running other process which is php – shealtiel Aug 10 '11 at 23:10
  • No. PHP is rarely (if ever) compiled into the webserver. Usually it's loaded as a library, which allows you to upgrade either without having to recompile both. – Marc B Aug 11 '11 at 14:09
0

For Linux, you could use $result = exec("which php");

For Windows, I saw this kind of link (I don’t know Windows enough I can verify it to work)

Smar
  • 8,109
  • 3
  • 36
  • 48
  • I find it funny that you say that about Windows. Usually Windows is the OS that most people know the most, even the techies. Though it is just not as powerful and flexible as Linux/Unix. – Patrick Aug 10 '11 at 22:46