Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between system and shell_exec

Tags:

shell

php

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?

like image 789
Ank Avatar asked May 29 '12 22:05

Ank


3 Answers

See the explanation here:

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

like image 83
sberry Avatar answered Oct 14 '22 02:10

sberry


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

like image 45
Ismael Vacco Avatar answered Oct 14 '22 03:10

Ismael Vacco


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.

like image 2
AvkashChauhan Avatar answered Oct 14 '22 02:10

AvkashChauhan