开发者

PHP: asking php the path to itself

开发者 https://www.devze.com 2023-03-27 11:13 出处:网络
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 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 th开发者_运维问答is information in runtime, so parsing the result of phpinfo() is less than ideal solution


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.


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消