Need help with PHP.

kkenny

Active Member
Messages
1,950
Reaction score
0
Points
36
Hey guys. I'm planning to do this new script for my x10Portal.

It's a server status script, but this time I'm going to add the percentage of uptime that the service is up.

This is my code
The main code
PHP:
<?php
function serverStatus($server, $port, $service, $serverName) {
$status = @fsockopen($server, $port, $errno, $errstr, 10);
if (!$status) {
echo "<div align='center'><font color='red' size='6'><blink>&bull;</blink></font></div>";
} else {
echo "<div align='center'><font color='green' size='6'>&bull;</font></div>";
fclose($status);
}
}
?>
The second part of the code for every individual service for every server.
PHP:
<?php
serverStatus("IP", PORT, "SERVICE NAME", "SERVER NAME")
?>

What I need is a php script that instead of just displaying the status of the server, I will also display the uptime percentage of that service right below that status.

Any ideas?
 

kkenny

Active Member
Messages
1,950
Reaction score
0
Points
36
Anything within x10 Free Hosting resources can be used to solve this problem.
 

pokefan2

New Member
Messages
24
Reaction score
0
Points
0
maye if you divide the total time that the server has been up by the total time the server has existed, multiply by 100, and added a % sign at the end, it would work.

Just an idea.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Showing the current status of the server is not hard, but if you want to show the uptime percentage, you'll need to know how long the site has been up and how long it has been down...
The only thing I can come up with is to make a cron every x minutes and if the server is online add x to the online counter, if the site is offline add x minutes to the offline counter. (So you'll need to store 2 integers as well.)
Then the maths to calculate the server uptime would be (online/(online + offline))*100 (in %).

In case you can't figure how to do it I could help you further.

- Marshian
 

kkenny

Active Member
Messages
1,950
Reaction score
0
Points
36
IDK how well to use Crons, but that's what I'm probably going to use after searching through PHP tutorials.

What I'm looking for is say I upload my server status script. From the time it's uploaded, I want to find the uptime of that service.
 
Top