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
  • 6,040
  • 22
  • 67
  • 100
  • 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
  • 128,281
  • 18
  • 138
  • 165
3

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

Ismael Vacco
  • 1,010
  • 1
  • 10
  • 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,495
  • 3
  • 34
  • 65