Home >Backend Development >PHP Tutorial >The difference and use of command execution functions in PHP learning

The difference and use of command execution functions in PHP learning

little bottle
little bottleforward
2019-04-19 17:24:502389browse

This article mainly talks about the differences and uses of command execution functions in PHP. It has certain learning value. Interested friends can take a look.

<?php
$cmd="ps aux|grep php-fpm";
$res=exec($cmd,$o);
var_dump($o);//数组形式返回,每行一个元素
var_dump($res);//字符串形式返回,只返回最后一行
echo "==============================================================\n\r";
$res=system($cmd);//直接把结果给输出到了屏幕
var_dump($res);//字符串形式返回的最后一行
echo "==============================================================\n\r";

$res=shell_exec($cmd);//屏幕打印所有结果
var_dump($res);//字符串返回所有结果
echo "==============================================================\n\r";

$res=passthru($cmd);//屏幕打印所有结果
var_dump($res);//不返回结果

Running results:

Related tutorials: PHP video tutorial

The above is the detailed content of The difference and use of command execution functions in PHP learning. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete