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

首頁 > 開發 > PHP > 正文

PHP調用linux命令詳細說明

2024-05-04 21:48:10
字體:
來源:轉載
供稿:網友

在php中調用linux命令的函數是

string exec(string command,string[array],int[return_var]); 

如:exec( "vpopmail ");echo exec('whoami');
 
再看一實例,代碼如下:
  1. function exec_enabled() { 
  2.   $disabled = explode(', 'ini_get('disable_functions')); 
  3.   return !in_array('exec'$disabled); 
  4. <?php  
  5. $tmp = exec("c:/Image/gm.exe convert c:/Image/file1.tiff c:/Image/file1.jpg"$results);  
  6. ?> 

還有一種命令是:php通過函數system()調用系統命令.

string system ( string $command [, int &$return_var ] )

實例:system('asterisk -vvvvvvvvvvvc');

system()是一樣的函數C的,它執行給定的命令和輸出結果的版本,該system()的調用也嘗試自動刷新網頁服務器的輸出緩沖器在每個輸出行如果PHP運行作為服務器模塊,如果你需要執行一個命令,并已全部通過直接從背面沒有任何干擾的命令數據,使用passthru()函數.

  1. $last_line = system('ls'$retval); 
  2. function my_exec($cmd$input='')  
  3.          {$proc=proc_open($cmdarray(0=>array('pipe''r'), 1=>array('pipe''w'), 2=>array('pipe''w')), $pipes);  
  4.           fwrite($pipes[0], $input);fclose($pipes[0]);  
  5.           $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);  
  6.           $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);  
  7.           $rtn=proc_close($proc);  
  8.           return array('stdout'=>$stdout,  
  9.                        'stderr'=>$stderr,  
  10.                        'return'=>$rtn  
  11.                       );  
  12.          } //開源代碼Vevb.com 
  13. var_export(my_exec('echo -e $(</dev/stdin) | wc -l''h/nel/nlo')); 

實例三,代碼如下:

  1. $cmd = "date"
  2.  
  3.    $output = system($cmd);  
  4.    printf("System Output: $output "); 
  5.  
  6.    exec($cmd$results);  
  7.    printf("Exec Output: {$results[0]} "); 

php調用linux命令的權限問題

你可以使用定時任務執行你要調用的php,這時的權限就是root,php通過函數system()調用系統命令.

php一般是以apache用戶身份去執行的,把apache加入到存儲你文件的父文件夾屬組里去,然后改該父文件夾權限為775,這樣屬組成員就有寫的權限,而apache屬于這個組就可以改寫該目錄下所有文件的權限,當然,屬組最好不要是root,你可以為該文件夾改個其它普通用戶組.

改apache/php的運行用戶方法不安全.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 岳阳市| 伊金霍洛旗| 山丹县| 扶余县| 城口县| 株洲县| 福州市| 汾西县| 麻江县| 弋阳县| 鄂州市| 博客| 新干县| 岳池县| 屏边| 射阳县| 松滋市| 钟祥市| 光山县| 运城市| 施甸县| 开鲁县| 连平县| 安多县| 芷江| 宜兴市| 宁海县| 友谊县| 郎溪县| 方城县| 宁化县| 盐池县| 金秀| 寿宁县| 稻城县| 富裕县| 钟山县| 永仁县| 叶城县| 贵南县| 务川|