加入收藏 | 设为首页 | 会员中心 | 我要投稿 开发网_开封站长网 (http://www.0378zz.com/)- 科技、AI行业应用、媒体智能、低代码、办公协同!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

在PHP函数如何运行Linux系统代码?这几个函数需知道

发布时间:2022-04-20 08:53:01 所属栏目:语言 来源:互联网
导读:在开发过程中,有时候我们会需要在PHP函数在运行Linux系统代码,那么我们就会使用到这些函数,shell_exec函数,exec函数,system函数,passthru函数,popen函数,proc_open函数。下面我们就来详细了解下PHP执行linux命令可能会用到的六个函数。 1,exec函数
       在开发过程中,有时候我们会需要在PHP函数在运行Linux系统代码,那么我们就会使用到这些函数,shell_exec函数,exec函数,system函数,passthru函数,popen函数,proc_open函数。下面我们就来详细了解下PHP执行linux命令可能会用到的六个函数。
 
        1,exec函数
 
<?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, 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
 
        以上就是PHP执行linux命令六个函数的介绍,通过上述函数,PHP就可以执行Linux命令啦,希望上述内容对大家学习有所帮助。

(编辑:开发网_开封站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读