


PHP調(diào)用Linux系統(tǒng)的常用函數(shù)
PHP調(diào)用Linux系統(tǒng)的常用函數(shù)
1、exec函數(shù)
<?php
$test = "ls /tmp/test"; //ls是linux下的查目錄,文件的命令
exec($test,$array); //執(zhí)行命令
print_r($array);
?>
2、system函數(shù)
<?php
$test = "ls /tmp/test";
$last = system($test);
print "last: $last\n";
?>
3、passthru函數(shù)
<?php
$test = "ls /tmp/test";
passthru($test);
?>
4、popen函數(shù)
<?php
$test = "ls /tmp/test";
$fp = popen($test,"r"); //popen打一個進(jìn)程通道
while (!feof($fp)) { //從通道里面取得東西
$out = fgets($fp, 4096);
echo $out; //打印出來
}
pclose($fp);
?>
5、proc_open函數(shù)
<?php
$test = "ls /tmp/test";
$arrayarray = array(
array("pipe","r"), //標(biāo)準(zhǔn)輸入
array("pipe","w"), //標(biāo)準(zhǔn)輸出內(nèi)容
array("pipe","w") //標(biāo)準(zhǔn)輸出錯誤
);
$fp = proc_open($test,$array,$pipes); //打開一個進(jìn)程通道
echo stream_get_contents($pipes[1]); //為什么是$pipes[1],因為1是輸出內(nèi)容
proc_close($fp);
?>
6、proc_open函數(shù)
<?php
$test = "ls /tmp/test";
$arrayarray = array(
array("pipe","r"), //標(biāo)準(zhǔn)輸入
array("pipe","w"), //標(biāo)準(zhǔn)輸出內(nèi)容
array("pipe","w") //標(biāo)準(zhǔn)輸出錯誤
);
$fp = proc_open($test,$array,$pipes); //打開一個進(jìn)程通道
echo stream_get_contents($pipes[1]); //為什么是$pipes[1],因為1是輸出內(nèi)容
proc_close($fp);
?>
7、shell_exec函數(shù)
<?php
$test = "ls /tmp/test";
$out = shell_exec($test);
echo $out;
?>
關(guān)鍵字:Linux、系統(tǒng)、PHP
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動項
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機IP講解
- CentOS7使用hostapd實現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯
- 解決Centos7雙系統(tǒng)后丟失windows啟動項
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解