Error on running exec command

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Error on running exec command

Post by Kadanis »

I hope this is the right forum, as this is a little bit php and a little bit Linux command line stuff

I am running the exec function to run a command on the box, which returns the current Exim queue size.

Code: Select all

$queue_size = exec('exim -bpc');
If I run this line of php via the command line, and echo the variable I get the results I'm looking for. However, when I run the same php page via a CRON job, instead of using the var in the code it emails me the following error

sh: exim: command not found.

Does anyone know what this means.? I understand something can't find the exim command, but I don't know what as this works perfectly from the command line.

Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There's an environment variable PATH that controls where the shell is looking for executables.
This variable can change from account to account. The webserver probably uses another account than you do when you're logged in.

You can compare the PATH settings with

Code: Select all

echo $PATH

Code: Select all

<?php echo 'path: ', $_ENV['PATH']; ?>
You can also let the shell (or a helper application) tell you which exim it invokes

Code: Select all

which exim
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post by Kadanis »

solved this, thought i'd post in case it helps anyone else.

php can't run commands without a full path to the binary (or at least thats what it took to fix this)

Code: Select all

echo exec('/usr/sbin/exim -bpc');
will return the right info.
Post Reply