Reputation: 41
I have done a couple hours of research and have found a solution, however I would prefer a solution without using the exec command.
Currently I have this code:
exec ("cat /proc/cpuinfo", $details);
$string= $details[4];
I basically would like it to pull the first processor's type, like that code does, but without using the system or exec command.
I would prefer to read directly from /proc/cpuinfo.
Upvotes: 4
Views: 9105
Reputation: 4512
Just put the code below:
<pre>
<strong>Uptime:</strong>
<?php system("uptime"); ?>
<br />
<strong>System Information:</strong>
<?php system("uname -a"); ?>
<br />
<strong>Memory Usage (MB):</strong>
<?php system("free -m"); ?>
<br />
<strong>Disk Usage:</strong>
<?php system("df -h"); ?>
<br />
<strong>CPU Information:</strong>
<?php system("cat /proc/cpuinfo | grep \"model name\\|processor\""); ?>
</pre>
And you will get something like :
Upvotes: 1
Reputation: 1
$cpuget = file('/proc/cpuinfo');
$cpu["name"] = str_replace(" ", " ",substr(str_replace("model name : ", "", $cpuget[4]),0,-1));
$cpu["cores"] = substr(str_replace("cpu cores : ", "", $cpuget[12]),0,-1);
$cpu["cache"] = substr(str_replace("cache size : ", "", $cpuget[8]),0,-1);
Upvotes: 0
Reputation: 237995
All you're doing is getting information from a file. This can be done with native PHP functions. The simplest way of doing this (and the most similar to your current solution) is with file
:
$file = file('/proc/cpuinfo');
$proc_details = $file[4];
Upvotes: 7
Reputation: 103
RECOMMENDATION: use file_get_contents() function is good, but you'd check php_open_basedir restriction and file existence.
Upvotes: 0