Re: [PHP] location of the PHP executable

2007-04-12 Thread Børge Holen
On Wednesday 11 April 2007 23:50, Jarrel Cobb wrote:
 Don't you have to run locate -u first to generate the database before using
 locate?  You can't just assume a database exists already can you?

not an updated one at least, updatedb can also be used to update.
and if you're in a little bit of hurry you can also use find -name some part 
of filename here


 On 4/11/07, Jim Lucas [EMAIL PROTECTED] 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
 
 
 
  --
  Enjoy,
 
  Jim Lucas
 
  Different eyes see different things. Different hearts beat on different
  strings. But there are times
  for you and me when all such things agree.
 
  - Rush
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php

-- 
---
Børge
http://www.arivene.net
---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-12 Thread Chris

Børge Holen wrote:

On Wednesday 11 April 2007 23:50, Jarrel Cobb wrote:

Don't you have to run locate -u first to generate the database before using
locate?  You can't just assume a database exists already can you?


not an updated one at least, updatedb can also be used to update.


Probably can't because the database has to be created as root.. unless 
you get into using the switches which seems like a lot more hassle than 
it's worth but *shrug*.


If this is for a cron command, try

env php

which should pick whichever is in the $PATH for the cron environment.

Not 100% guaranteed but 90% should work.

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-12 Thread Davi
Em Quarta 11 Abril 2007 19:38, Buesching, Logan J escreveu:
   IF db not exists THEN
 locate -u
   END-IF

 I'd hate to see the time it'd take to create a first-time database...
 this could take awhile to run.


_maybe_ locate -u is faster than ls / -Rv... Need to test before said 
anything... =P

# df -h
Sist. Arq.Tam   Usad Disp  Uso% Montado em
/dev/hda3  18G   16G  473M  98% /
udev  506M  752K  506M   1% /dev
cachedir   18G   16G  473M  98% /lib/splash/cache
shm   506M 0  506M   0% /dev/shm
/dev/sda1 112G  112G  249M 100% /mnt/win2
/dev/sdb1 150G  132G   18G  89% /mnt/win3
/dev/hdb1  75G   37G   39G  49% /mnt/win1

maybe I test both here... XD

# time locate -u  time locate combate.php

real23m19.453s
user0m6.600s
sys 0m20.200s
/mnt/win1/Documents and Settings/Davi/Desktop/stellar/codigo/php/combate.php
/mnt/win1/Documents and Settings/Davi/Meus 
documentos/stellar/codigo/php/combate.php
/mnt/win3/backup 021106/Desktop/jogos/combate.php
/mnt/win3/backup 021106/Desktop/stellar/combate.php
/mnt/win3/backup 021106/Desktop/stellar/stellar/combate.php
/mnt/win3/backup 021106/Desktop/stellar/stellar/site/combate.php
/home/davi/stellar/codigo/php/combate.php

real0m1.680s
user0m0.520s
sys 0m0.060s


I'm trying to find anything using ls...

ls / -Rv | grep -iE combate.php$

But I can't retrieve the entire path yet... u.u'
But time seen to be the same...


Sorry poor english...

[]s

-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--

Agora com fortune:
Never trust an operating system you don't have sources for.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Jim Lucas

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



--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different strings. But there are times 
for you and me when all such things agree.


- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Jarrel Cobb

Don't you have to run locate -u first to generate the database before using
locate?  You can't just assume a database exists already can you?

On 4/11/07, Jim Lucas [EMAIL PROTECTED] 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



--
Enjoy,

Jim Lucas

Different eyes see different things. Different hearts beat on different
strings. But there are times
for you and me when all such things agree.

- Rush

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] location of the PHP executable

2007-04-11 Thread Davi
Em Quarta 11 Abril 2007 18:50, Jarrel Cobb escreveu:
 Don't you have to run locate -u first to generate the database before using
 locate?  You can't just assume a database exists already can you?


If you can use locate, you can use which... =P

BTW, do something to check OS then:

IF OS == *nix THEN
  IF exists /usr/bin/which THEN
which php
  ELSE
IF exists /usr/bin/locate THEN
  IF db not exists THEN
locate -u 
  END-IF
  locate php | grep -iE php$
ELSE
  IF exists /usr/bin/find THEN
find / -name php | grep -iE php$
  ELSE
 cd /  ls php -Rv
  END-IF
   END-IF
  END-IF
ELSE
  cd \
  dir php*.exe /s
END-IF


Check if I don't miss any END-IF... =P

[]s

-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--

Agora com fortune:
rugged, adj.:
Too heavy to lift.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] location of the PHP executable

2007-04-11 Thread Buesching, Logan J
  IF db not exists THEN
locate -u 
  END-IF

I'd hate to see the time it'd take to create a first-time database...
this could take awhile to run.

-Original Message-
From: Davi [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 11, 2007 6:10 PM
To: php-general@lists.php.net
Subject: Re: [PHP] location of the PHP executable

Em Quarta 11 Abril 2007 18:50, Jarrel Cobb escreveu:
 Don't you have to run locate -u first to generate the database before
using
 locate?  You can't just assume a database exists already can you?


If you can use locate, you can use which... =P

BTW, do something to check OS then:

IF OS == *nix THEN
  IF exists /usr/bin/which THEN
which php
  ELSE
IF exists /usr/bin/locate THEN
  locate php | grep -iE php$
ELSE
  IF exists /usr/bin/find THEN
find / -name php | grep -iE php$
  ELSE
 cd /  ls php -Rv
  END-IF
   END-IF
  END-IF
ELSE
  cd \
  dir php*.exe /s
END-IF


Check if I don't miss any END-IF... =P

[]s

-- 
Davi Vidal
[EMAIL PROTECTED]
[EMAIL PROTECTED]
--

Agora com fortune:
rugged, adj.:
Too heavy to lift.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Jochem Maas
Mattias Thorslund wrote:
 Jim Lucas wrote:
...

 $ /my-location-of/php myscript.php
 /my-location-of/php
 $
 
 I was hoping there's a function or $_SERVER property that would contain
 this?

have you tried looking for this info you want?
I can't say for sure if it always exists but on the few boxes
I tried I found and entry in both $_SERVER and $_ENV:

_ = '/usr/bin/php'

but that was only on linux.
on windows (where my php cli install is a bit borked),
I didn't find it but I did find PHPRC which points to
the directory that the php executable lives in.

these maybe of some use.
then again what ever it is your trying to do with the php script
you seem to need to run inside another instance of php could probably
be run within the context of the calling script - if you run it inside
a function you can stop any kind of variable scope clashes (assuming there are
no symbol name clashes [e.g. duplicate functions/classes]):

function runit()
{
include 'myscript.php';
}

it's just a thought.
 
 Thanks again,
 
 Mattias
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Richard Lynch
On Wed, April 11, 2007 2:49 pm, Mattias Thorslund wrote:
 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?

The generalized answer to any question of this nature is:

If the answer you want isn't in ?php phpinfo();? output, then the
answer you want probably isn't available.

In *my* installation:
which php
yields:
/usr/bin/php

Then:
php -i | grep /usr/bin/php
yields $_SERVER[_] and $_ENV[_]

No promise this works for any/all platforms, however.

PS For the 'locate' sub-thread -- You can't even guarantee that
'locate' will be available, much less initialized...  I don't think
it's a good solution, in general.

YMMV
NAIAA
IANAL

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Mattias Thorslund
Jochem Maas wrote:

  have you tried looking for this info you want?

   

Yup, but the manual seems kind of light on the subject.


  I can't say for sure if it always exists but on the few boxes
  I tried I found and entry in both $_SERVER and $_ENV:
 
  _ = '/usr/bin/php'

   

I found these in $_ENV and $_SERVER, on Linux. I don't have handy access
to a working Windows installation, yet it needs to work on Windows as well.

If it really does exist on Windows, this might be the ticket, otherwise
a partial solution for Linux only.


  but that was only on linux.
  on windows (where my php cli install is a bit borked),
  I didn't find it but I did find PHPRC which points to
  the directory that the php executable lives in.

   

That's at least something. If someone could confirm, that would be great.

I used the following command (at the command-line) to check the contents
of $_SERVER:

php -r 'print_r($_SERVER);'

Obviously, $_ENV can be checked similarly.


  these maybe of some use.

   

Yes very useful, thanks.


  then again what ever it is your trying to do with the php script
  you seem to need to run inside another instance of php could probably
  be run within the context of the calling script - if you run it inside
  a function you can stop any kind of variable scope clashes (assuming there 
  are
  no symbol name clashes [e.g. duplicate functions/classes]):
 
  function runit()
  {
  include 'myscript.php';
  }
 
  it's just a thought.

   

Unfortunately, I think it's not an option in my case. The sub-process I
run this way are way, way too big to include in the main process.  As
long as I was just running it on my own systems, it was easy to
hard-code the location of the PHP executable but now that it's being
distributed, it needs to just work...

Thanks again,

Mattias

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] location of the PHP executable

2007-04-11 Thread Jochem Maas
your script should try it's best to find the executable, on failure
you might consider having it mail an error to you so at least you
can pre-empt the client with regard to getting things working.

most windows machines will probably have there php binary at:

$_ENV['PHPRC'].'php.exe'

variations on the exe name can be (IIRC):

'php-win.exe'
'php-cli.exe'

I think you can be pretty sure about $_ENV['_'] on *nix
systems.

another to consider is a simple installer which tries to
find the exe and on failure offers the user a prompt to say where it
is .. that info can then be stored for use at a later date.

Mattias Thorslund wrote:
 Jochem Maas wrote:
 
 have you tried looking for this info you want?
   
   
 
 Yup, but the manual seems kind of light on the subject.
 
 
 I can't say for sure if it always exists but on the few boxes
 I tried I found and entry in both $_SERVER and $_ENV:

 _ = '/usr/bin/php'
   
   
 
 I found these in $_ENV and $_SERVER, on Linux. I don't have handy access
 to a working Windows installation, yet it needs to work on Windows as well.
 
 If it really does exist on Windows, this might be the ticket, otherwise
 a partial solution for Linux only.
 
 
 but that was only on linux.
 on windows (where my php cli install is a bit borked),
 I didn't find it but I did find PHPRC which points to
 the directory that the php executable lives in.
   
   
 
 That's at least something. If someone could confirm, that would be great.
 
 I used the following command (at the command-line) to check the contents
 of $_SERVER:
 
 php -r 'print_r($_SERVER);'
 
 Obviously, $_ENV can be checked similarly.
 
 
 these maybe of some use.
   
   
 
 Yes very useful, thanks.
 
 
 then again what ever it is your trying to do with the php script
 you seem to need to run inside another instance of php could probably
 be run within the context of the calling script - if you run it inside
 a function you can stop any kind of variable scope clashes (assuming there 
 are
 no symbol name clashes [e.g. duplicate functions/classes]):

 function runit()
 {
 include 'myscript.php';
 }

 it's just a thought.
   
   
 
 Unfortunately, I think it's not an option in my case. The sub-process I
 run this way are way, way too big to include in the main process.  As
 long as I was just running it on my own systems, it was easy to
 hard-code the location of the PHP executable but now that it's being
 distributed, it needs to just work...
 
 Thanks again,
 
 Mattias
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php