温馨提示×

php命令执行函数有哪些

PHP
养鱼的猫咪
195
2021-03-24 10:01:25
栏目: 编程语言

php命令执行函数有哪些

php中的命令执行函数有System、Exec和Passthru几种

1.System函数

System函数作用:

php中System函数的作用是用于执行command参数所指定的命令,且打印全部的输出值。

System函数语法:

system ( string $command , int &$return_var = ? ) : string

参数:

command:需要执行的命令。

return_var:外部命令执行后的返回状态将会被设置到此变量中。

System函数使用方法:

$v = system('netstat -tnlp',$shell_return);

var_dump($shell_return);

var_dump($v);

2.Exec函数

Exec函数作用:

php中Exec函数的作用是用于执行command参数所指定的命令,且不打印任何内容。

Exec函数语法:

exec ( string $command , array &$output = ? , int &$return_var = ? ) : string

Exec函数使用方法:

$out = ['a'=>'apple','b'=>'banana','c'=>'cat','d'=>'dog'];

$shell_return=null;

$v = exec('netstat -tnlp',$out,$shell_return);

print_r($out);

var_dump($shell_return);

var_dump($v);

3.Passthru函数

Passthru函数作用:

php中Passthru函数的作用是用于执行外部程序并且显示原始输出。

Passthru函数语法:

passthru ( string $command , int &$return_var = ? ) : void

参数:

command:需要执行的命令。

return_var:Unix命令的返回状态会被记录到此参数。

Passthru函数使用方法:

passthru('ls', $return_val);

echo 'Exit code of $return_val\n';

0