Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Script - Get Server Processor

Tags:

php

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.

like image 982
Jacob Avatar asked Sep 14 '25 04:09

Jacob


2 Answers

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];
like image 133
lonesomeday Avatar answered Sep 15 '25 18:09

lonesomeday


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 : enter image description here

like image 28
Sid Avatar answered Sep 15 '25 19:09

Sid