Both of these functions execute Linux command functions, except that the return result is not the same, exec can only get the last line of data, and Shell_execu gets all the data.
If the script path has the following file:
Copy Code code as follows:
-bash-4.1# LL
Total Dosage 12
-rw-rw-r--. 1 www web 133 July 15:00 a.php
-rw-r--r--. 1 Lee Web 59 February 17:05 b.php
-rw-r--r--. 1 Lee Web 81 March 8 17:00 c.php
exec Example
Copy Code code as follows:
<?php
/**
* The difference between exec and shell_exec
* Jones Taiwan Blog
*/
$data = EXEC ('/bin/ls-l ');
Echo ' <pre> ';
Print_r ($data);
Echo ' </pre> ';
?>
Execution results
Copy Code code as follows:
-rw-r--r--. 1 Lee Web 8 17:00 c.php
shell_exec Example
Copy Code code as follows:
<?php
/**
* The difference between exec and shell_exec
* Jones Taiwan Blog
*/
$data = shell_exec ('/bin/ls-l ');
Echo ' <pre> ';
Print_r ($data);
Echo ' </pre> ';
?>
Execution results
Copy Code code as follows:
Total 12
-rw-rw-r--. 1 www web 139 June a.php
-rw-r--r--. 1 Lee Web Feb 17:05 b.php
-rw-r--r--. 1 Lee Web 8 17:00 c.php
So usually use the EXEC function of the children's shoes attention, if you need to get all the return information, you should use the Shell_exec function, of course, if the command execution results only one line to return information, then use which does not matter.