The difference between the exec function and the shell_exec function in PHP is execshell_exec. The difference between the exec function and the shell_exec function in PHP. execshell_exec function both execute the Linux command function. The difference is that the returned result is different, exec can only obtain the number of the last row. The difference between the exec function and the shell_exec function in PHP is: 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:
The 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
The code is as follows:
<? Php
/**
* What is the difference between exec and shell_exec?
* Qiongtai blog
*/
$ Data = exec ('/bin/ls-L ');
Echo'
';
print_r($data);
echo '
';
?>
Execution result
The code is as follows:
-Rw-r --. 1 lee web 81 Mar 8 c. php
Example of shell_exec
The code is as follows:
<? Php
/**
* What is the difference between exec and shell_exec?
* Qiongtai blog
*/
$ Data = shell_exec ('/bin/ls-L ');
Echo'
';
print_r($data);
echo '
';
?>
Execution result
The 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.
Both functions are run Linux command functions. The difference is that the returned results are different. exec can only get the number of the last row...