Home > php教程 > php手册 > body text

PHP执行Linux命令常用的6个函数

WBOY
Release: 2016-06-13 10:40:59
Original
869 people have browsed it

  一般情况下,很少会用php去执行linux命令,不过特殊情况下,你也许会用到这些函数。以前我知道有二个函数可以执行linux命令,一个是exec,一个是shell_exec。其实有很多的,结合手册内容,介绍以下6个函数。

  1,exec函数

<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span>     </span></span></li>
<li>
<span>$</span><span class="attribute">test</span><span> = </span><span class="attribute-value">"ls /tmp/test"</span><span>;   //ls是linux下的查目录,文件的命令     </span>
</li>
<li class="alt"><span>exec($test,$array);       //执行命令     </span></li>
<li><span>print_r($array);     </span></li>
<li class="alt">
<span class="tag">?></span><span>   </span>
</li>
</ol>
Copy after login

  返回结果如下:

 

<ol class="dp-xml">
<li class="alt"><span><span>[root@krlcgcms01 shell]# php ./exec.php     </span></span></li>
<li><span>Array     </span></li>
<li class="alt"><span>(     </span></li>
<li>
<span> [0] =</span><span class="tag">></span><span> 1001.log     </span>
</li>
<li class="alt">
<span> [1] =</span><span class="tag">></span><span> 10.log     </span>
</li>
<li>
<span> [2] =</span><span class="tag">></span><span> 10.tar.gz     </span>
</li>
<li class="alt">
<span> [3] =</span><span class="tag">></span><span> aaa.tar.gz     </span>
</li>
<li>
<span> [4] =</span><span class="tag">></span><span> mytest     </span>
</li>
<li class="alt">
<span> [5] =</span><span class="tag">></span><span> test1101     </span>
</li>
<li>
<span> [6] =</span><span class="tag">></span><span> test1102     </span>
</li>
<li class="alt">
<span> [7] =</span><span class="tag">></span><span> weblog_2010_09     </span>
</li>
<li><span>)  </span></li>
</ol>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template