Milind Ganjoo
Milind Ganjoo

Reputation: 1280

Running shell_exec() in symfony

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.

Upvotes: 1

Views: 7382

Answers (3)

Milind Ganjoo
Milind Ganjoo

Reputation: 1280

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.

Upvotes: 3

Jason B
Jason B

Reputation: 23

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

Upvotes: 0

johnwards
johnwards

Reputation: 1901

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

Upvotes: 0

Related Questions