Home >Backend Development >PHP Tutorial >Introduction to the usage of php's system() function & exec() function & passthru() function
This article brings you an introduction to the usage of PHP's system() function & exec() function & passthru() function. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. helped.
Specific usage of functions
As a newbie like me, I don’t even know how to use php system, so I will make a simple record today.
system() outputs and returns the last line of shell results.
exec() does not output results and returns the last line of shell results. All results can be saved in a returned array.
passthru() only calls the command and outputs the command execution result directly to the standard output device as is.
<?php echo '<pre class="brush:php;toolbar:false">'; // 输出 shell 命令 "ls" 的返回结果 // 并且将输出的最后一样内容返回到 $last_line。 // 将命令的返回值保存到 $retval。 $last_line = system('ls', $retval); // 打印更多信息 echo '
The returned result is the result after executing the command in Linux (it turns out that this is the usage, but I am still too good)
<pre class="brush:php;toolbar:false">anaconda-post.log bin code dev entrypoint.sh etc home lib lib64 media mnt opt proc root run run.sh sbin srv sys tmp usr var
Related recommendations:
The complete code for PHP to implement bubble sorting and binary search
The above is the detailed content of Introduction to the usage of php's system() function & exec() function & passthru() function. For more information, please follow other related articles on the PHP Chinese website!