PHP打印显示树莓派状态信息

将下面的代码复制下来保存为php页面,访问这个页面就能查看实时的树莓派状态信息了。原理是打印shell_exec的结果。 sudo cat /proc/cpuinfo 可以查看当前CPU的信息 sudo cat /proc/iomem 可以查看当前IO映射的信息,也就是GPU内部的信息

<?php
    /**
    * state
    *
    * @package custom
    */
?>
    <article class="content">
    <section class="post">
        <div id='server_state'>
            <h5>uname -a</h5>
            <pre><?php echo shell_exec("uname -a"); ?></pre><br/>
     
            <h5>Uptime</h5>
            <pre><?php echo ltrim(shell_exec("uptime"), " "); ?></pre><br/>
     
            <h5>cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq </h5>
            <pre>
                <?php
                    $t = shell_exec("cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
            echo sprintf("%s/1000=%sKHz", str_replace("\n", "", $t), $t/1000);
                ?>
            </pre><br/>
     
            <h5>cat /sys/class/thermal/thermal_zone0/temp </h5>
            <pre>
                <?php
                    $t = shell_exec("cat /sys/class/thermal/thermal_zone0/temp");
        echo sprintf("%s/1000=%sC°", str_replace("\n", "", $t), $t/1000);
       ?>
      </pre><br/>
     
            <h5>free -h</h5>
            <pre><?php echo shell_exec("free -h"); ?></pre><br/>
     
            <h5>cat /proc/cpuinfo</h5>
            <pre><?php echo shell_exec("cat /proc/cpuinfo"); ?></pre>
                 
            <h5>cat /proc/iomem</h5>
            <pre><?php echo shell_exec("cat /proc/iomem"); ?></pre>
</div>

via

Licensed under CC BY-NC-SA 4.0
最后更新于 Jun 12, 2016 09:59 UTC