tags:

views:

26

answers:

3

Hi,

I have a program that returns a comma-separated string of numbers after doing some background processing. I intended to run this in symfony using shell_exec; however, all I get is NULL (revealed through a var_dump(). I tried the following debugging steps.

I ran the file (it's a PHP class) through a command-line lime unit test in Symfony - it works and gives the correct result there.

Just to check, I tried a simple command ls -l at the same place to see whether I would get anything. Again, I had the same problem - the var_dump in the browser showed NULL, but it worked through the command line.

What could be the problem? Are there restrictions on running shell_exec() in a browser?

EDIT: Just to clarify, shell_exec() commands work when I run them as standalone php scripts on the web server (for example, by putting them in my document root. They don't seem to be working under the symfony framework, for some reason.

A: 

Have you tried using exec? Or one of the other variants. I am never sure of which one to use and always lump with exec.

http://uk.php.net/manual/en/function.exec.php

johnwards
No; I tried with exec(), system() and the backtick operators, and still nothing.
mganjoo
A: 

Is your web server running php in safe mode?

Note: This function is disabled when PHP is running in safe mode. From: http://php.net/manual/en/function.shell-exec.php

Jason B
No; I did a check of phpinfo(), and safe_mode is Off.
mganjoo
Is this your server or a shared hosting? They could have disabled shell_exec in the php.ini for the web server.
Jason B
No, it's my own apache server on my Ubuntu box. And shell_exec() commands *do* work when I run them through the browser as standalone PHP files in the document root.
mganjoo
A: 

I finally solved it, and it turned out to be something quite simple, and quite unrelated.

The shell command I was running was in this format: face_query -D args. I didn't realize that Apache would be executing PHP as user www-data and thus the program face_query wouldn't be in the PATH (the directory is actually ~/bin). Changing the program name to the full path of the program solved it.

I also gather from this that only commands which www-data has permission to execute can be run. In this case, www-data is in the same group as my user, but it might be a problem otherwise.

mganjoo