Re: [PHP] location of the PHP executable



Jim Lucas wrote:
Mattias Thorslund wrote:
Hi,

I have looked in the documentation but can't find it:

My PHP script (which is run from the command prompt - CLI) needs to know
the file system location of the PHP executable. This is because it needs
to run a second PHP script. I know about the "which" command but it's
not available in all OSes, and that might not be the currently running
executable anyway.

I could prompt the user for this, but that seems kind of silly. Surely,
there must be some way of looking it up automatically?

Thanks,

Mattias


What OS are you working with

Assuming you are on a *nix box this should work

#locate "/php" | grep "/php$"

this should give you locations that have /php as the end of the line


on windows you could do this

cd \
dir /s php*.exe

Thanks Jim (and others) for the suggestions. I think they will be helpful if there
isn't a way to do what I'm looking for:

Ideally, I would like to get the location of the PHP executable that is
actually executing the script. I'm thinking there would be some way to
find out while the script is executing. Something like:

<?php
$executable_location = get_location_of_current_executable();
//fictitious function
echo $executable_location ."\n";
?>

Running it from the command line (again fiction):

$ /my-location-of/php myscript.php
/my-location-of/php
$

I was hoping there's a function or $_SERVER property that would contain
this?

Thanks again,

Mattias
.



Relevant Pages

  • Re: mod_rexx vs. mod_php performance
    ... |%> slow if compared to php), ... | If you want to compare performance, ... | the time it starts executing, and finishing after it finishes executing. ... |% gets issued to the current command environment as a command. ...
    (comp.lang.rexx)
  • Re: [PHP] ssh command in php script
    ... > I have written the following command in PHP script ... > when the execute the php file from the browser it does ... scalable system for accessing system services | ...
    (php.general)
  • [UNIX] PHP Allows Bypassing of safe_mode And Injecting ASCII Control Chars With mail()
    ... PHP is a widely used general-purpose scripting language that is especially ... vulnerabilities exists in mailPHP function. ... within a PHP script. ... allow specifying command line option to the sendmail binary. ...
    (Securiteam)
  • Re: Forking PHP on Windows 2003.
    ... > php script and have the first scrip continue to completion. ... if Windows itself allows it. ... However, if you type HELP START from your Windows command prompt, ...
    (comp.lang.php)
  • Executing an application whose directory path contains blank spaces
    ... I can't find a way to execute a Windows application, ... contains blank spaces, from a PHP script. ... The problem doesn't happen if the command parameters are not double quoted: ...
    (comp.lang.php)