PHP执行linux命令的6个函数
<?php $test = 'ls /tmp/test'; //ls是linux下的查目录,文件的命令exec($test,$array); //执行命令print_r($array);?> 返回结果如下:
[root@krlcgcms01 shell]# php ./exec.php Array ( [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函数
<?php $test = 'ls /tmp/test';$last = system($test);print 'last: $lastn';?> 返回结果:
[root@krlcgcms01 shell]# php system.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 last:weblog_2010_09 3,passthru函数
<?php $test = 'ls /tmp/test';passthru($test);?> 4,popen函数
<?php $test = 'ls /tmp/test';$fp = popen($test,'r'); //popen打一个进程通道 while (!feof($fp)) { //从通道里面取得东西 $out = fgets($fp, 4096); echo $out; //打印出来} pclose($fp);?> 5,proc_open函数
<?php $test = 'ls /tmp/test';$array = array( array('pipe','r'), //标准输入 array('pipe','w'), //标准输出内容 array('pipe','w') //标准输出错误 ); $fp = proc_open($test,$array,$pipes); //打开一个进程通道echo stream_get_contents($pipes[1]); //为什么是$pipes[1],因为1是输出内容proc_close($fp);?> 6,shell_exec函数
<?php $test = 'ls /tmp/test';$out = shell_exec($test);echo $out;?> popen,passthru,proc_open,shell_exec的返回结果如下:
[root@krlcgcms01 shell]# php test.php 1001.log 10.log 10.tar.gz aaa.tar.gz mytest test1101 test1102 weblog_2010_09 我能发现的就这几个函数,能执行linux下的命令,我想应当还有吧,欢迎大家补充。 来自:http://blog.51yip.com/php/1064.html
相关文章:
