PHP shell

php怎么执行shell命令

小亿
272
2023-09-19 14:40:23
栏目: 编程语言
PHP开发者专用服务器,限时0元免费领! 查看>>

要在PHP中执行shell命令,可以使用exec()函数、shell_exec()函数或system()函数。

  1. exec()函数:
exec(command, output, return_var);

示例:

exec('ls -l', $output, $return_var);
print_r($output); // 输出命令执行结果
echo $return_var; // 输出命令返回值
  1. shell_exec()函数:
$output = shell_exec(command);

示例:

$output = shell_exec('ls -l');
echo $output; // 输出命令执行结果
  1. system()函数:
system(command, return_var);

示例:

system('ls -l', $return_var);
echo $return_var; // 输出命令返回值

注意:

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:php执行shell命令时间太长怎么解决

0
看了该问题的人还看了