显示树莓派状态信息的PHP页面

将下面的代码复制下来保存为php页面,访问这个页面就能查看实时的树莓派状态信息了。原理是打印shell_exec的结果。

<?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>
</div>

via

这是一篇发布于 11年 前的文章,其中的信息可能已经有所发展或是发生改变,请了解。


8 评论

    • 空白有两个原因,第一:权限问题,当你访问这个页面的时候,是以当前执行php用户的身份去访问的,例如nginx用户是www,这个用户权限肯定不够。第二:php安全问题,php会把这些shell_exec这一类的可以调用脚本的功能给禁掉,你需要修改php.ini配置文件。

    • 可以执行,但是你要给执行php的用户root权限,具体你可以参考我上面的回复,点击头像可以去我的博客找到一些解答。

raspiweb进行回复 取消回复

你的邮件地址不会公开


*