In general, php is rarely used to execute linux commands, but in special cases, you may use these functions. I used to know that there are two functions that can execute linux commands, one is exec and the other is shell_exec. This article will introduce the summary of common functions used to execute linux commands in PHP, if you need a friend, you may rarely use php to execute linux commands. However, in special cases, you may use these functions. I used to know that there are two functions that can execute linux commands, one is exec and the other is shell_exec. through this article, I will introduce you to the summary of common functions used to execute linux commands in PHP.
In general, php is rarely used to execute linux commands, but in special cases, you may use these functions. I used to know that there are two functions that can execute linux commands: exec and shell_exec. In fact, there are a lot of functions. the following six functions are introduced in combination with the manual content.
1. exec function
The returned results are as follows:
[root@krlcgcms01 shell]# php ./exec.phpArray([0] => 1001.log[1] => 10.log[2] => 10.tar.gz[3] => aaa.tar.gz[4] => mytest[5] => test1101[6] => test1102[7] => weblog_2010_09)
2. system functions
Returned results:
[root@krlcgcms01 shell]# php system.php1001.log10.log10.tar.gzaaa.tar.gzmytesttest1101test1102weblog_2010_09last:weblog_2010_09
3. passthru function
4. popen function
5. proc_open function
6. shell_exec function
Popen, passthru, proc_open, and shell_exec return the following results:
[root@krlcgcms01 shell]# php test.php1001.log10.log10.tar.gzaaa.tar.gzmytesttest1101test1102weblog_2010_09
I can find out that these functions can execute commands in linux. I think there should be some more.
For more articles about common functions used to execute linux commands in PHP, refer to PHP Chinese network!