我只是想知道 php 中是否有一种方法可以检索服务器的属性,例如计算机名称、内存、处理器信息。
这些信息将被加载到 ActionScript 中。
我已经用这种方式创建了一个 php 文件来了解服务器的 IP 地址,就像网上教程文章中所述的那样:
<?php //Opening Tag, tell PHP server to interpret the following lines as php code
$ip = $_SERVER['REMOTE_ADDR']; //Sets the ip variable, its value is a method that will get the user ip
echo $ip; //The echo keyword outputs the assigned string, in this case the ip variable
?>
我已成功将 IP 地址的值回显或显示到我的 Flash 应用程序。现在,我不知道如何知道服务器的计算机名称、内存和处理器信息。
这里有人知道 php 中的代码来显示我需要的信息吗?
编辑: 感谢您的快速回复。
这就是答案。我们必须使用exec命令。 (考虑到php没有配置安全功能或者被关闭)
了解一台电脑的计算机名称。
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
对于PC的CPU和内存:
<?php
function GetProgCpuUsage($program)
{
if(!$program) return -1;
$c_pid = exec("ps aux | grep ".$program." | grep -v grep | grep -v su | awk {'print $3'}");
return $c_pid;
}
function GetProgMemUsage($program)
{
if(!$program) return -1;
$c_pid = exec("ps aux | grep ".$program." | grep -v grep | grep -v su | awk {'print $4'}");
return $c_pid;
}
echo "CPU use of Program: ".GetProgCpuUsage($randomprogram)."%";
echo "Memuse of Program: ".GetProgMemUsage($randomprogram)."%";
?>
您可以更多地引用此信息的来源。 来源:http://php.net/manual/en/function.exec.php
最佳答案
在服务器中创建一个脚本,该脚本将获取其硬件信息并将其显示给您。之后通过 actionscript
调用此脚本并显示信息。
要获取硬件信息,您需要系统命令。您必须使用exec
函数来运行系统命令。
要获取 Windows 操作系统的系统信息,请使用此命令 systeminfo
。 System info for windowsOS
关于php 文件 actionscript 计算机属性 RAM 处理器信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16297173/