免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2437 | 回复: 1
打印 上一主题 下一主题

PHP调用Linux系统的常用函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-19 21:25 |只看该作者 |倒序浏览
PHP调用Linux系统的常用函数








  为了方便广大考生更好的复习,帮考网综合整理提供了Linux认证HP调用Linux系统的常用函数,以供各位考生考试复习参考,希望对考生复习有所帮助。  PHP调用Linux系统的常用函数  1、exec函数  <?php  ...       为了方便广大考生更好的复习,帮考网综合整理提供了Linux认证HP调用Linux系统的常用函数,以供各位考生考试复习参考,希望对考生复习有所帮助。

  PHP调用Linux系统的常用函数

  1、exec函数
  1.   <?php

  2.   $test = "ls /tmp/test"; //ls是linux下的查目录,文件的命令

  3.   exec($test,$array); //执行命令

  4.   print_r($array);

  5.   ?>
复制代码
2、system函数
  1.  <?php

  2.   $test = "ls /tmp/test";

  3.   $last = system($test);

  4.   print "last: $last\n";

  5.   ?>
复制代码
3、passthru函数
  1. [code]  <?php

  2.   $test = "ls /tmp/test";

  3.   passthru($test);

  4.   ?>
复制代码
[/code]

  4、popen函数
  1.  <?php

  2.   $test = "ls /tmp/test";

  3.   $fp = popen($test,"r"); //popen打一个进程通道

  4.   while (!feof($fp)) { //从通道里面取得东西

  5.   $out = fgets($fp, 4096);

  6.   echo $out; //打印出来

  7.   }

  8.   pclose($fp);

  9.   ?>
复制代码
5、proc_open函数

  1.   <?php

  2.   $test = "ls /tmp/test";



  3.   $arrayarray = array(

  4.   array("pipe","r"), //标准输入

  5.   array("pipe","w"), //标准输出内容

  6.   array("pipe","w") //标准输出错误

  7.   );

  8.   $fp = proc_open($test,$array,$pipes); //打开一个进程通道

  9.   echo stream_get_contents($pipes[1]); //为什么是$pipes[1],因为1是输出内容

  10.   proc_close($fp);

  11.   ?>
复制代码
6、proc_open函数
  1.   <?php

  2.   $test = "ls /tmp/test";

  3.   $arrayarray = array(

  4.   array("pipe","r"), //标准输入

  5.   array("pipe","w"), //标准输出内容

  6.   array("pipe","w") //标准输出错误

  7.   );

  8.   $fp = proc_open($test,$array,$pipes); //打开一个进程通道

  9.   echo stream_get_contents($pipes[1]); //为什么是$pipes[1],因为1是输出内容

  10.   proc_close($fp);

  11.   ?>
复制代码
7、shell_exec函数
  1.  <?php

  2.   $test = "ls /tmp/test";

  3.   $out = shell_exec($test);

  4.   echo $out;

  5.   ?>
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-03-19 21:26 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP