Here are just a few common shell commands, some commands that require root user privileges, see: PHP executes shell commands with root privileges
PHP executes shell commands and can use several functions:
String system (string $command [, int & $return _var]) string exec (string $command [, array & $output [, int & ; $return _var]]) void PassThru (string $command [, int & $return _var])
Note That: These three functions are forbidden by default, if you want to use these functions, you must first modify the PHP configuration file php.ini, Find the keyword disable_functions, remove the function names from this item, and then pay attention to restarting Apache.
first look at the system () and PassThru () two functions are similar, interchangeable:
<?php $shell = "ls-la"; Echo "<pre>"; System ($shell, $status); Echo "</pre>"; Note the corresponding relationship between the execution of the shell command and the status value returned $shell = "<font color= ' red ' > $shell </font>"; If ($status) { echo "shell command {$shell} failed to execute"; } else { Echo "shell command {$shell} executed successfully"; }? >
The results of the implementation are as Follows:
Note that system () will display the results immediately after executing the shell command, which is inconvenient because we do not need the results to be output immediately or even output, so we can use the Exec ()
example of the use of exec ():
<?php $shell = "ls-la"; EXEC ($shell, $result, $status); $shell = "<font color= ' red ' > $shell </font>"; Echo "<pre>"; If ($status) { echo "shell command {$shell} failed to execute"; } else { Echo "shell command {$shell} executed successfully with the result as follows
The results of the operation are as Follows:
Shell script--php Execute shell command