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.
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 userwww-dataand 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-datahas permission to execute can be run. In this case,www-datais in the same group as my user, but it might be a problem otherwise.