PHP [Linux Servers] Operating System and Processor Installed

Code that the staff think is particularly good will be copied here.
Locked
User avatar
Hustle
Posts: 24
Joined: Wed Jul 27, 2011 1:30 pm
Location: United Kingdom

PHP [Linux Servers] Operating System and Processor Installed

Post by Hustle »

jacek wrote:This is an archive post, any discussion should take place here viewtopic.php?f=5&t=556


Hi,

Below are a few lines of PHP code I've used before on linux servers and thought I should share on here :D , a small contribution to the BetterPHP Community but every contribution however big or small helps :D.

How to find out the processor that's installed in a linux server.
[syntax=php]<?php
$proc = (explode(":",shell_exec("cat /proc/cpuinfo | grep \"model name\"")));
echo "<b>Processor:</b>$proc[1]";
?>[/syntax]Result on my local linux server:
Processor: AMD Athlon(tm) II P320 Dual-Core Processor


How to find out the operating system that's installed on a linux server.
[syntax=php]<?php
$serveros = (explode(":",shell_exec("lsb_release -d")));
echo "<b>Operating System:</b>$serveros[1]";
?>[/syntax]Result on my local linux server:
Operating System: Ubuntu 10.04.3 LTS


Enjoy :D , I hope this will be useful to others.
Locked