How to get the full path to php interpreter / binary without shell access

后端 未结 4 939
北恋
北恋 2020-12-17 16:37

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;
         


        
相关标签:
4条回答
  • 2020-12-17 16:57

    Linux users can try the whereis command.

    I had this situation with a PHP IDE.

    whereis php
    
    0 讨论(0)
  • 2020-12-17 17:15

    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

    0 讨论(0)
  • 2020-12-17 17:16

    its not common for a host to give root access to its users. Most probably, you can't access anything below /var/www

    0 讨论(0)
  • 2020-12-17 17:19

    On Windows I would suggest the following snippet:

    <?php
    $pid = getmypid();
    $output = shell_exec(sprintf('tasklist /nh /fo csv /fi "PID eq %d"', $pid));
    $processInfo = explode(',', $output);
    echo PHP_BINDIR . DIRECTORY_SEPARATOR . trim($processInfo[0], '"');
    

    On unix the shell command should probably make use of ps

    0 讨论(0)
提交回复
热议问题