Php exec () function not working for all commands on ubuntu + nginx + fpm

I see the result:

echo exec("whoami"); // will output "www-data"

      

however, if I try to run the real world command:

echo exec("casperjs myscript.js /foo/bar");

      

then nothing happens:

  • no output (casperjs script should output some stdout log messages)
  • no action (the script should create an image using an absolute path, but it doesn't)
  • errors with PHP
  • no shell command output

I searched on StackOverflow and went to try alternative ways (checked in the shell first to make sure they work):

echo exec("casperjs /absolute/path/to/myscript.js");
echo exec("/usr/local/bin/casperjs /absolute/path/to/myscript.js");

      

I have tested also other combinations using system()

, shell_exec()

and even passthru()

but it is always the same: no error, no output, even in php log files, so it is very difficult to understand the problem :(

+3


source to share


1 answer


Try echo exec("casperjs myscript.js /foo/bar 2>&1");

redirecting stderr to stdout, which would not be displayed otherwise.



It could be a bug in your cmdline, or maybe casperjs doesn't have your $ PATH, etc.

+2


source







All Articles