Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP shell_exec() vs exec()

I'm struggling to understand the difference between shell_exec() and exec()...

I've always used exec() to execute server side commands, when would I use shell_exec()?

Is shell_exec() just a shorthand for exec()? It seems to be the same thing with fewer parameters.

like image 866
Webnet Avatar asked Aug 17 '11 13:08

Webnet


People also ask

What is PHP exec function?

The exec() function is an inbuilt function in PHP which is used to execute an external program and returns the last line of the output. It also returns NULL if no command run properly. Syntax: string exec( $command, $output, $return_var )

What is shell exec?

Updated: 05/04/2019 by Computer Hope. On Unix-like operating systems, exec is a builtin command of the Bash shell. It lets you execute a command that completely replaces the current process. The current shell process is destroyed, and entirely replaced by the command you specify.

How do I run a PHP script in Linux?

You can execute linux commands within a php script - all you have to do is put the command line in brackits (`). And also concentrate on exec() , this and shell_exec() ..


1 Answers

shell_exec returns all of the output stream as a string. exec returns the last line of the output by default, but can provide all output as an array specifed as the second parameter.

See

  • http://php.net/manual/en/function.shell-exec.php
  • http://php.net/manual/en/function.exec.php
like image 51
Daniel A. White Avatar answered Sep 22 '22 11:09

Daniel A. White