Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to read my CPU temperature with PHP, but I cannot find the relevant info. All paths under /proc/acpi/thermal_zone appear empty. I have tried:

  • /proc/acpi/thermal_zone/THM0/temperature
  • /proc/acpi/thermal_zone/THRM/temperature
  • /proc/acpi/thermal_zone/THR1/temperature

None of these (appear to) exist. What is the correct path to the CPU temperature monitor?

phpinfo() says:

PHP Version 5.4.12
Linux infong 2.4 #1 SMP Thu Feb 14 13:02:49 CET 2013 i686 GNU/Linux
Safe mode is off
Apache
share|improve this question
    
Seconding zorlem, the temperature sensor is not a useful way to seed a PRNG. Get your entropy from /dev/urandom, that's what it's for. –  Gilles Apr 5 '13 at 21:33
    
@Gilles Since we are here in unix.SE and PHP questions are posed and answered in Stackoverflow, I was (obviously, I thought) aiming at receiving an answer explaining how to read my CPU temperature. The part about seeding a PRNG is irrelevant here, and I have edited my question accordingly. –  what Apr 6 '13 at 4:48
add comment

1 Answer

The thermal zones temperatures for each core are available from /sys/class/thermal/thermal_zone?/temp on kernel versions > 3.x.

Your desire to seed mt_rand() using your CPU temperature makes no sense. According to the mt_rand() documentation, seeding the PRNG is done automatically in PHP versions 4.2.0+. Even if you want to seed it manually using mt_srand(), doing so using your CPU temperature is an extremely bad idea. Most of the CPUs maintain a pretty constant temperature of operation (eg. 46⁰C) and the recent intel "i" processors (i3, i5, i7), the cores are simply switched off when not needed - so the temperature is 0. You're much better leaving it to default (not specifying a seed value), than trying to seed the PRNG with a constant value.

Also, if you need the mt_rand() for generating any crypto values make sure to read the warinings in the documentation - it does not produce cryptographically secure random numbers.

share|improve this answer
    
/sys is empty on my system. Thank you for the thoughts on seeding mt_rand. I'll think about that. –  what Apr 5 '13 at 10:31
    
The phpinfo() output in your question looks incomplete. What version is the kernel on the server? –  zorlem Apr 5 '13 at 15:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.