PHP is in my opinion a good language - it allows you to do "interactive" websites, so called Web 2.0. With it, you can create truly developed projects - from social networking sites to online stores.
In his time in PHP began to "Internet computer monitoring systems". We have a server and want to see if it works and what is its status. PHP scripts that have a lot of MB code are usually used by this code interpreter, and you must have an entire web server.
My micro-project consists in creating a simple script in Bash which, using Busybox (httpd) and shell scripts, will make a very simple page to monitor the server.
1) Server
The server here will be the httpd located in the Busybox. Busybox is a "Swiss knife for computers" - an application that basically replaces hundreds of other applications - of course console.
The command used is:
busybox httpd -p 10123 -h $PWD
Busybox, run applet (module) httpd on port 10123, and get page data from the directory where the user is currently located.
Content generator
Httpd works by default on HTML files. You can actually add PHP, but in my opinion this is not necessary. We will use the Bash script, which will create a new index.html data file every 10 seconds. This is not the best method, but the only one I know.
I created a simple Bash code that uses a loop - every 10 seconds it generates a new portion of the data.
i=0
while [ $i -lt 1 ]
do
echo '<html><head><META HTTP-EQUIV="refresh" CONTENT="5; URL="index.html"></head><body>' > index.html
screenfetch -N -n -w -p >> index.html
echo '<br>' >> index.html
sensors >> index.html
date >> index.html
sed -e 's/$/<br>/' -i index.html
echo "</body></html>" >> index.html
sleep 10s
done
What does it do? It initializes the variable "i" to 0. The While loop will execute code contained in it until it is equal to 1 (ie never). Using screenfetch, free and date writes data to the index.html file. These data are eg a computer processor, CPU temperature, current date, RAM usage, and so on.
Sed will add a new tag
to each line.
Sleep 10s will sleep the program for 10 seconds.
3) Merge
Personally, I created 3 files:
- One that launches the entire server and generator
busybox httpd -p 10123 -h $PWD
busybox sh $PWD/generator.sh
Generator itself
Shown above :)Turn off server and generator
killall -9 busybox
This post received a 1.1% upvote from @randowhale thanks to @fervi! For more information, click here!
I would like to clarify one thing. When you say that PHP allows people to build interactive so-called Web 2.0 websites, it is kind of like saying, that the use of "red cars" allows people to drive on roads.
Every server side language, that has the capability to evaluate parameters of http requests (user input) and to create specific output based on this input, can be used to create Web 2.0 applications/websites.
Web 2.0 has to be seen as a concept, and has nothing to do with a specific server side language.
I like your idea and I didn't know about BusyBox, seems to be a pretty tool. Few years ago I made some windows queries in order to gather this information.
Busybox is only for Linux? I'm not used to work on Linux. I do my work on windows. :)