mridang_agarwal Posted June 13, 2007 Share Posted June 13, 2007 is there a way to get the path of the php executable through code? i want to run to a few command line scripts and my main script should detect the PHP CLI path automatically. Quote Link to comment Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 You would need to write a bash wrapper (assuming your using Linux). #!/bin/bash p=$(which php) exec $p yourscript.php Quote Link to comment Share on other sites More sharing options...
mridang_agarwal Posted June 13, 2007 Author Share Posted June 13, 2007 hi thorpe. Could be a bit more thorough. I couldn't follow you. Is there a common solution both Windows and Unix systems? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted June 13, 2007 Share Posted June 13, 2007 But why do you need that ?? Ask your hosting company they will tell you that Information. Quote Link to comment Share on other sites More sharing options...
trq Posted June 13, 2007 Share Posted June 13, 2007 Is there a common solution both Windows and Unix systems? Nope. Windows isn't terribly scriptable by default. I'm not even sure it comes with a default scripting language.. Maybe vbscript? but as far as I know windows also does not have any utilities for detecting where executables are located within a user PATH. Explain exactly what it is your trying to do. A shebang line is probably all your looking for, but then again, I don't think these effect windows. Quote Link to comment Share on other sites More sharing options...
mridang_agarwal Posted June 14, 2007 Author Share Posted June 14, 2007 okay, heres what i need to ge done exactly. I have a PHP script that i need to execute from the command line. This script is executed by another script. Script A executes script B using exec(path/to/php -f scriptb.php); I need to know path to PHP right? Quote Link to comment Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 I need to know path to PHP right? If your creating command line scripts they should have a shabang as there first line. eg; #!/usr/bin/php This tells the shell how to execute the program (Linux). I could almost guarantee that that will be the location of php on all Linux installs. If not, it will at least link to the actual executable. As for windows, sorry, but I have no idea. You could probably try searching the user PATH variable (which I'de assume you can get through $_ENV['PATH']), but it wont be pretty. You say your calling your script via exec(path/to/php -f scriptb.php), if this is happening from within a php script why not simply use include()? Quote Link to comment Share on other sites More sharing options...
mridang_agarwal Posted June 14, 2007 Author Share Posted June 14, 2007 i want my script to run as a daemon so i decided to make it run from the command line. Quote Link to comment Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 i want my script to run as a daemon so i decided to make it run from the command line. Sorry, what comment are you referring to? Is this an excuse for not using include(). If so, it makes no sense. You only need to call the initiating script form the command line. Quote Link to comment Share on other sites More sharing options...
neel_basu Posted June 14, 2007 Share Posted June 14, 2007 If PHP CLI is Installed in your server And If you just use php -f yourscript.php It should work. if it doesnt work ask your host. Quote Link to comment Share on other sites More sharing options...
trq Posted June 14, 2007 Share Posted June 14, 2007 if it doesnt work ask your host. You keep saying 'ask your host'. How do you know the OP is not trying to develop a deployable application? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted June 14, 2007 Share Posted June 14, 2007 if it doesnt work ask your host. You keep saying 'ask your host'. How do you know the OP is not trying to develop a deployable application? [i've provided him alternatives also] Hosting Companies server is set up in such a way that you have permission to do a very few things in shell and with that you cant do any deployable application. But I think they should tell him. else rely upon PHP CLI php -f yourscript.php Cause we dont know where is the php is it in bin or sbin ----------------------------------------------------- See your PATH it would be like PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games Check with all of this 1 By 1 e.g. /usr/local/sbin/php /usr/local/bin/php /usr/sbin/php Bla Bla ...... Else ----------------------------------- Can you read your .profile if yes get the value of PATH from it and check in teh Previous way else ----------------------------------------- Make a shell script and in it try using php -f yourscript.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.