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
Release: 2023-04-06 06:50:01
forward
2407 people have browsed it

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);//不返回结果
Copy after login

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!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template