6

What is the difference between shell_exec and system methods in PHP?

Both take a single command line argument and runs that within PHP. Is it better to use one over the other?

Ank
  • 5,704
  • 21
  • 62
  • 97
  • Can't you just read the docs for [`shell_exec`](http://php.net/manual/en/function.shell-exec.php) and [`system`](http://php.net/manual/en/function.system.php)? – James Allardice May 29 '12 at 22:04

3 Answers3

4

See the explanation here:

http://chipmunkninja.com/Program-Execution-in-PHP%3A-exec-m@

sberry
  • 121,970
  • 18
  • 133
  • 163
3

With system is possible to capture the return code. Already with the shell_exec is not possible.

Ismael Vacco
  • 970
  • 1
  • 8
  • 24
2

I think the main different is when PHP is running in safe mode. System will still work with some restriction as described in documentation however shell_exec will be disabled.

AvkashChauhan
  • 20,355
  • 3
  • 32
  • 64