Home  >  Article  >  Backend Development  >  Use php to execute shell command under linux to view the server's machine name_PHP tutorial

Use php to execute shell command under linux to view the server's machine name_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:07:301076browse

I came across a small need today.

How to display the server’s machine name in a web page,
In Ubuntu, just enter the command: uname -n to see (the same is true for Redhat),
So I wonder if php can directly call the shell command to perform this operation?
After checking the information,
I learned that there is indeed one, and there are several of them:
popen
fpassthru
shell_exec
exec
system
Read how to use it,
It seems that shell_exec is relatively simple. You only need to pass in the command as parameters,
And it directly returns the result after executing the command,
So I tried it:
< ?php
shell_exec('uname -n');
?>
Successfully displayed the machine name of the current server.
However, if it is a purchased server, the test may not be successful,
Because for security reasons, the server provider may disable some or all of them

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477863.htmlTechArticleI encountered a small need today. How to display the server’s machine name in a web page. In Ubuntu, just Enter the command: uname -n to see (the same is true for Redhat), so I wonder if php can directly...
Statement:
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