View Full Version : Print Processor Type and RAM using php

02-01-2007, 01:07 PM

I want to know whether if there is any php function or any script that prints the system processor type and RAM available. Is it possible to get system information using any built in php functions.

Thanks in advance

02-01-2007, 06:10 PM
I dont think you can do this with PHP functions but you may beable to use the EXEC command to execute a bash file which outputs this information.

02-02-2007, 11:31 AM
I have tried this in my php script by using file_get_contents("/proc/cpuinfo"). But as this file is read protected , it is displaying a error message that it cannot be read. How can i read the contents of this read protected file.

02-02-2007, 11:37 AM
unsure about reading the file but have you tried executing it


that may work

02-02-2007, 12:44 PM

I did the same using shell_exec(). It is giving the following error:
Error: Cannot execute using backquotes in SAFE MODE.

Thanks in Advance

02-07-2007, 08:14 AM
I have done this using system function
system ( vi '/proc/cpuinfo').

But to save the entire output into a variable
$sysstat = print system(vi '/proc/cpuinfo')

But $sysstat contains only the first line . How can i print the entire information present in cpuinfo.

Thanks in Advance

02-07-2007, 09:37 AM
well i have never come across that error message vefore hand which is very weird.

The other option that may work is this...

$fp = fopen("/proc/cpuinfo", "r");
while ($data = fread($fp, 1024)){
$cpuinfo .= $data;
echo $cpuinfo;

That may work depending on how php is setup, it will read the cpuinfo in as a file line by line and store it in the cpuinfo variable

02-07-2007, 10:27 AM
But the file is read protected, i am not able to read the file in ' r' mode.

Thanks in Advance

02-07-2007, 10:28 AM
The file /proc/cpuinfois under root privileges. It has neither read nor write permission.


02-07-2007, 10:37 AM
i see, well I am away from the office at the moment but there are several other executing commands on php that you can try,


and failing that there are some function I myself have never used but they may work

that is meant to open a process and allow you to read / write to it but I have never had the need to use it.

Just being curiouse but why do you need the processor spec?

02-07-2007, 12:46 PM
Its a device ... but still a file in 'everything is a file' Linux style.
but this should still work even as an unprivileged user ?

exec('cat /proc/cpuinfo',$yaks);

02-07-2007, 07:10 PM
on both my home machine and my shared-hosting account I, as a non-root user, can read /proc/cpuinfo and /proc/meminfo.

if you couldn't read the file, then your vi example wouldn't work either...surely?

02-08-2007, 11:04 AM
Yes , in my machine the /proc/cpuinfo are read protected. So I am unable to read it by using any of your suggested methods. Is there any other alternative

Thanks in Advance

02-08-2007, 11:48 AM
Right I have had time to do a few test for you and if you visit you will see some working code showing that my server runs on a dual 3Ghz CPU's

CPU Information (http://www.paramiliar.com/cpuinfo.php)

The code to show this is as follows

exec ("cat /proc/cpuinfo", $details);

$processor1 = $details[1]."<br />".$details[4]."<br />".$details[6]."<br />".$details[7];
$processor2 = $details[47]."<br />".$details[50]."<br />".$details[52]."<br />".$details[53];

echo "Processor 1 <br>$processor1<br /><br />Processor 2 <br />$processor2";

Hope that helps, if for any reason it doesn't work post the URL to the file for me and I may be able to bug test it from the output

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum