【问题标题】:php file actionscript computer properties ram processor informationphp 文件 actionscript 计算机属性 ram 处理器信息
【发布时间】:2013-04-24 05:06:30
【问题描述】:

我只是想知道php中是否有一种方法可以检索服务器的属性,例如计算机名称、内存、处理器信息。

这些信息将被加载到一个动作脚本中。

我已经以这种方式完成了一个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 
?>

我已经成功地向我的 Flash 应用程序回显或显示 IP 地址的值。现在,我不知道如何知道服务器的计算机名称、内存和处理器信息。

这里有没有人知道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

【问题讨论】:

  • 否 - 但您可以调用程序并读取响应或从提供此信息的伪文件系统中读取 - 但这些是特定于操作系统的。 (你没有说这是用于什么操作系统)。
  • 看看你的代码,你似乎在尝试重新发明轮子——这些东西大部分都是在开源许可下现成的——使用更合理的架构——例如见exchange.nagios.org/directory/Addons/Monitoring-Agents/…
  • 感谢这个想法。我以前从来不知道这一点。我会试试这个东西。

标签: php actionscript ip


【解决方案1】:

在服务器中创建一个脚本,该脚本将获取其硬件信息并将其显示给您。然后通过actionscript调用这个脚本并显示信息。

要获取硬件信息,您需要系统命令。您必须使用exec 函数来运行系统命令。

要获取 Windows 操作系统的系统信息,请使用此命令systeminfoSystem info for windowsOS

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 2011-08-02
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多