View Full Version : [all variants] show temp on website

May 5th, 2010, 05:50 PM
iam trying to show cpu temp on my website but i have no idea how to start with this.

i tryed to make a symlink to

but i have no clue if what iam doing is even acomplised like this

could some one please help me to show the cpu temp via php

May 5th, 2010, 06:57 PM
You could probably just do this:

print file_get_contents('/proc/acpi/thermal_zone/TZ00/temperature');

but my path is a little different, so you might want to make it work regardless of the directory name "TZ00", and perhaps add some error detection.

print getCpuTemp()."\n";

function getCpuTemp() {
return 'N/A';
foreach($temp as $d) {
return trim(file_get_contents($path));
return 'N/A';

May 5th, 2010, 09:26 PM
thanks for your reply

i tryed this:
print file_get_contents('/proc/acpi/thermal_zone/TZ00/temperature');?>

but i just get a empty page ?
just as with the symlink

May 5th, 2010, 09:29 PM
Can you get the temperature at all?

cat /proc/acpi/thermal_zone/TZ00/temperature

May 5th, 2010, 09:46 PM
yeah that does work
this is the output:

$ cat /proc/acpi/thermal_zone/TZ00/temperature
temperature: 43 C

i can also cat the symlink (if that mathers)

May 5th, 2010, 09:51 PM
ls -l /proc/acpi/thermal_zone/TZ00/temperature
echo "<?php print file_get_contents('/proc/acpi/thermal_zone/TZ00/temperature');?>"|sudo tee /var/www/cputemp.php
sudo chmod 644 /var/www/cputemp.php
sudo apt-get install php5-cli
php /var/www/cputemp.php
echo -e "GET /cputemp.php HTTP/1.0\n"|nc 80
tail /var/log/apache2/access.log
tail /var/log/apache2/error.log

May 5th, 2010, 10:28 PM
after i tryed :

ls -l /proc/acpi/thermal_zone/TZ00/temperature
echo "<?php print file_get_contents('/proc/acpi/thermal_zone/TZ00/temperature');?>"|sudo tee /var/www/cputemp.php
sudo chmod 644 /var/www/cputemp.php

it worked :) i have no clue what i did wrong and i dont really understand what happened just for my clarification

ls -l /proc/acpi/thermal_zone/TZ00/temperature ^shows the file permissions

echo "<?php print file_get_contents('/proc/acpi/thermal_zone/TZ00/temperature');?>"|sudo tee /var/www/cputemp.phpabout this part iam unsure it pasts the part of the code you commented earlier in to a file called cputemp.php
right ?

thanks a lot for your help :)

May 6th, 2010, 12:01 AM
can someone please explain to me how to let php execute a command like df for disk information or a easy way to output commands into a readable file
i tried
echo exec('whoami');
but it didn't work and i dont know how to enable it

ah it was php savemode that prohibited me from executing scripts

May 6th, 2010, 01:20 AM
Also, "exec" only returns the last line of output. You probably want "shell_exec".