久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

PHP執行linux命令6個函數代碼實例

瀏覽:93日期:2022-09-08 16:49:27

一般情況下,很少會用php去執行linux命令,不過特殊情況下,你也許會用到這些函數。以前我知道有二個函數可以執行linux命令,一個是exec,一個是shell_exec。其實有很多的,結合手冊內容,介紹以下6個函數。

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,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下的命令,我想應當還有吧,歡迎大家補充。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: PHP
相關文章:
主站蜘蛛池模板: 台前县| SHOW| 长顺县| 伽师县| 巴楚县| 涿州市| 正定县| 罗城| 闽侯县| 包头市| 乌兰察布市| 临潭县| 沧源| 南充市| 湄潭县| 潜山县| 运城市| 乳山市| 霍林郭勒市| 沙雅县| 于都县| 城市| 江西省| 资兴市| 辰溪县| 西藏| 青冈县| 雅安市| 鞍山市| 黑龙江省| 营山县| 巩留县| 新乐市| 乌审旗| 琼中| 辽中县| 泰来县| 隆尧县| 康马县| 镇沅| 忻州市|