国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

PHP執行linux命令常用函數匯總

2024-09-04 11:42:25
字體:
來源:轉載
供稿:網友

一般情況下,很少會用php去執行linux命令,不過特殊情況下,你也許會用到這些函數。以前我知道有二個函數可以執行linux命令,一個是exec,一個是shell_exec,通過本文給大家介紹PHP執行linux命令常用函數匯總,需要的朋友參考下。

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

1,exec函數

  1. <?php  
  2. $test = "ls /tmp/test"//ls是linux下的查目錄,文件的命令 
  3. exec($test,$array); //執行命令 
  4. print_r($array); 
  5. ?> 

返回結果如下:

  1. [root@krlcgcms01 shell]# php ./exec.php  
  2. Array  
  3. (  
  4. [0] => 1001.log  
  5. [1] => 10.log  
  6. [2] => 10.tar.gz  
  7. [3] => aaa.tar.gz  
  8. [4] => mytest  
  9. [5] => test1101  
  10. [6] => test1102  
  11. [7] => weblog_2010_09  

2,system函數

  1. <?php  
  2. $test = "ls /tmp/test"
  3. $last = system($test); 
  4. print "last: $last/n"
  5. ?> 

返回結果:

  1. [root@krlcgcms01 shell]# php system.php  
  2. 1001.log  
  3. 10.log  
  4. 10.tar.gz  
  5. aaa.tar.gz  
  6. mytest  
  7. test1101  
  8. test1102  
  9. weblog_2010_09  
  10. last:weblog_2010_09 

3,passthru函數

  1. <?php  
  2. $test = "ls /tmp/test"
  3. passthru($test); 
  4. ?> 

4,popen函數

  1. <?php  
  2. $test = "ls /tmp/test"
  3. $fp = popen($test,"r"); //popen打一個進程通道 
  4.  
  5. while (!feof($fp)) { //從通道里面取得東西 
  6. $out = fgets($fp, 4096); 
  7. echo $out//打印出來 
  8. }  
  9. pclose($fp); 
  10. ?> 

5,proc_open函數

  1. <?php  
  2. $test = "ls /tmp/test"
  3. $array = 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,shell_exec函數

  1. <?php  
  2. $test = "ls /tmp/test"
  3. $out = shell_exec($test); 
  4. echo $out
  5. ?> 

popen,passthru,proc_open,shell_exec的返回結果如下:

  1. [root@krlcgcms01 shell]# php test.php  
  2. 1001.log  
  3. 10.log  
  4. 10.tar.gz  
  5. aaa.tar.gz  
  6. mytest  
  7. test1101  
  8. test1102  
  9. weblog_2010_09 

我能發現的就這幾個函數,能執行linux下的命令,我想應當還有吧,歡迎大家補充。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 伊吾县| 资中县| 会宁县| 定陶县| 仁化县| 全椒县| 金溪县| 罗定市| 墨玉县| 弥渡县| 调兵山市| 汉中市| 隆尧县| 喀喇沁旗| 饶平县| 利辛县| 克拉玛依市| 鱼台县| 宁晋县| 商丘市| 惠水县| 牡丹江市| 江北区| 武清区| 龙南县| 万山特区| 海门市| 大悟县| 贡嘎县| 班玛县| 米泉市| 皮山县| 青铜峡市| 邢台县| 平果县| 嫩江县| 拉萨市| 方正县| 东阿县| 峨眉山市| 克山县|