What is the difference between the exec function and the shell_exec function in PHP? execshell_exec
Both of these functions execute Linux Command functions. The difference is that the returned results are different. exec can only obtain the last row of data, while shell_execu can obtain all the data.
Assume that the script path contains the following files:
Copy codeThe Code is as follows:
-Bash-4.1 # ll
Total usage 12
-Rw-r --. 1 www web 133 July 16 15:00 a. php
-Rw-r --. 1 lee web 59 February 29 17:05 B. php
-Rw-r --. 1 lee web 81 March 8 17:00 c. php
Exec example
Copy codeThe Code is as follows:
<? Php
/**
* What is the difference between exec and shell_exec?
* Qiongtai blog
*/
$ Data = exec ('/bin/ls-l ');
Echo '<pre> ';
Print_r ($ data );
Echo '</pre> ';
?>
Execution result
Copy codeThe Code is as follows:
-Rw-r --. 1 lee web 81 Mar 8 c. php
Example of shell_exec
Copy codeThe Code is as follows:
<? Php
/**
* What is the difference between exec and shell_exec?
* Qiongtai blog
*/
$ Data = shell_exec ('/bin/ls-l ');
Echo '<pre> ';
Print_r ($ data );
Echo '</pre> ';
?>
Execution result
Copy codeThe Code is as follows:
Total 12
-Rw-r --. 1 www web 139 Jul 16 2012 a. php
-Rw-r --. 1 lee web 59 Feb 29 :05 B. php
-Rw-r --. 1 lee web 81 Mar 8 c. php
Therefore, when using the exec function, note that if you need to obtain all the returned information, you should use the shell_exec function. Of course, if the command execution result contains only one row of returned information, it doesn't matter which one to use.
Execute the shell_exec function in php in linux.
Shell_exec ("/usr/local/bin/%2swf/home/xiazai/03.pdf-o/home/xiazai/1.swf;/usr/local/bin/%2swf/home/xiazai/2.jpg- o/home/xiazai/2.swf ");
Add a semicolon to each command
How to enable the EXEC function in PHPini
First, disable the security mode safe_mode = off.
Then look at the disabled function list.
Disable_functions = proc_open, popen, exec, system, shell_exec, passthru
Here we need to remove exec
Restart apache.