PDA

View Full Version : server uptime


ChronicleX.com
05-23-2005, 04:07 PM
Is there away to get your Server up time in php also it's speed cpu ram and page load time?

delinear
05-23-2005, 04:16 PM
What do you mean by page load time? If you mean the time it takes to execute the script on the server, you can add a little code to the beginning and end of the script like so:

//put this bit at the top of the page...
$time_start = microtime(true);

//put this bit at the very end of the page...
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Script execution time: $time seconds\n";

ChronicleX.com
05-23-2005, 04:18 PM
cool thanks

what about server up time? How would i do that?

delinear
05-23-2005, 04:24 PM
Well the following works for me on a *nix server:
$input = shell_exec('uptime');
$output = explode(" up ", $input);
$output = explode(",", $output[1]);
$output = $output[0];
echo $output;
If you're on a different OS or *nix flavour it might not work but you can give it a try. Should tell you the server uptime in days. As for the other stuff... not sure, sorry.

ChronicleX.com
05-23-2005, 04:53 PM
it works but.

How would i get that to also do hours and mins as well? What you done there is past my know how.

delinear
05-23-2005, 05:03 PM
Ah, try this:
$input = shell_exec('uptime');
$output = explode(" up ", $input);
$output = explode(",", $output[1]);
$output = $output[0] . ", " . $output[1];
echo $output;

ChronicleX.com
05-23-2005, 05:11 PM
hmmmm it says 82 days, 18:00

hours:mins right?

yeh great thanks just changed to 18:01

where do i put echo so i can put hours 18 mins 01 ?

i always wanted i server uptime display :thumbsup: just the other stuff


i sort of done it



$input = shell_exec('uptime');
$output = explode(" up ", $input);
$output = explode(",", $output[1]);
$output = $output[0] . ", Hours, " . $output[1] ;
echo "Server up time ";
echo $output;





ahhhh no wait needs to be the other end

it shows Server up time 82 days, Hours, 18:09

i need it

Server up time 82 days, 18 Hours, 09 Mins

Velox Letum
05-23-2005, 06:45 PM
$input = shell_exec('uptime');
$output = explode(" up ", $input);
$output = explode(",", $output[1]);
$h_m = explode(":", $output[1]);
$output = $output[0] . ", " . $h_m[0] . " Hours, " . $output[1] . " Minutes";
echo "Server up time " . $output;

ChronicleX.com
05-23-2005, 08:33 PM
hmmm i get this

Server up time 82 days, 21 Hours, 21:22 Minutes

what do you get?

how do you take off the 21: in the minutes?

Auriga
05-23-2005, 08:55 PM
I get the same too...

Server up time 12 days, 5 Hours, 5:48 Minutes

5:48 Minutes???

ChronicleX.com
05-23-2005, 09:38 PM
how you take of the 21: bit on the min area? any one know?

Ökii
05-23-2005, 10:48 PM
change $output[1] to $h_m[1]

ChronicleX.com
05-23-2005, 11:57 PM
did not work



$input = shell_exec('uptime');
$output = explode(" up ", $input);
$output = explode(",", $output[1]);
$h_m = explode(":", $output[1]);
$output = $output[0] . ", " . $h_m[0] . " Hours, " . $h_m[1] . " Minutes";
echo "Server up time " . $output;



????? :confused:

Velox Letum
05-24-2005, 12:14 AM
I apologise for the oversight on forgetting to change the $output[1] variable to $h_m[1], however the fixed code when uploaded to my website works just fine.

http://area51.nanoshock.net/uptime.php

ChronicleX.com
05-24-2005, 08:45 AM
yeh it started working on mine

http://www.chroniclex.com/downloads/scripts/serverinfo.php

i think when it's not got to the 1st hour it goes freaky?

SeeIT Solutions
05-24-2005, 10:35 AM
Is there anyway to show how long the server has been up in the last month? For example say

Server uptime in last 30 days = 29 days 20 hours 10 seconds (99.44%)

Thanks

delinear
05-24-2005, 10:57 AM
I don't really know how you'd do that but you could probably achieve it with some kind of cron job that updates every minute and writes a log to the database if the server's up then you work out how many logs would have been written in 30 days if the server had 100% uptime, count all the logs written in the last 30 days and find the difference... yeah, sounds a bit daunting to me, too :o

I'm sure there is an apache module that will generate stats. If it's configured on your server you could grab those results via PHP but other than that, I'm open to suggestions.

ChronicleX.com
05-24-2005, 01:35 PM
Is there away to get your Server up time in php also it's speed cpu ram and page load time?

any body got the answer to the rest of my Q's :confused:

ChronicleX.com
05-24-2005, 01:36 PM
Is there anyway to show how long the server has been up in the last month? For example say

Server uptime in last 30 days = 29 days 20 hours 10 seconds (99.44%)

Thanks

thats a good idea for a hosting company to show there server uptime :)

SeeIT Solutions
05-24-2005, 02:14 PM
That's my plan ;)

ChronicleX.com
05-24-2005, 02:23 PM
well i would like to have that script so i can see how well griffin.com is doing for my hosting. they have very good support but uptime i have no idea. i would like to know there ram and cpu speed as well. Is that spying :D

delinear
05-24-2005, 02:42 PM
Most hosts will tell you the CPU speed and RAM of the server you're on along with the uptime of the server (usually this is in some kind of SLA so they have to tell you to make sure they're meeting the SLA). If they withold basic information like that I'd consider changing hosts anyway!

As for the script - I've never seen a script that gets the CPU and RAM of the server (I'm not sure that's even possible) but such a script wouldn't tell you much as a programmer. They have nothing to do with the load that's placed on the server anyway (a slower server with less RAM may still outperform a fast server with lots of RAM if it's hosting less sites and there is less traffic, etc, less database queries, etc), the script execution times are much more important for comparative purposes.

ChronicleX.com
05-24-2005, 02:58 PM
Most hosts will tell you the CPU speed and RAM of the server you're on along with the uptime of the server (usually this is in some kind of SLA so they have to tell you to make sure they're meeting the SLA). If they withold basic information like that I'd consider changing hosts anyway!

As for the script - I've never seen a script that gets the CPU and RAM of the server (I'm not sure that's even possible) but such a script wouldn't tell you much as a programmer. They have nothing to do with the load that's placed on the server anyway (a slower server with less RAM may still outperform a fast server with lots of RAM if it's hosting less sites and there is less traffic, etc, less database queries, etc), the script execution times are much more important for comparative purposes.


.....................

i can ask my host anytime what the hardware the server has but i want to look for away to have a script update the info when they upgrade my host has very good support staff so don't need to move.

to some cheap USA $1 hosting company.


Thanks for the reply any way and the help ;)

of couse the RAM and cpu effect the speed of the server you have 100 ppl on the low spec and 100 ppl on the high spec it's going to make a difference in some way shape or form (also useing the same script). thats just my view though it's just me though lol

SeeIT Solutions
05-24-2005, 03:16 PM
Since I'm guessing that your CPU and RAM don't get upgraded that often and the viewers of your site wouldn't care couldn't you just ask your hosts what type of servers they have and ask for specs?

delinear
05-24-2005, 03:30 PM
of couse the RAM and cpu effect the speed of the server you have 100 ppl on the low spec and 100 ppl on the high spec it's going to make a difference in some way shape or form (also useing the same script). thats just my view though it's just me though lol

I didn't say that these things don't affect the speed of the server - I said that these things along tell you absolutely nothing at all. You could be on a 4Ghz server with 8Gb RAM and sharing with only one other person but if that person is running processes which use all the CPU clock cycles and fill the server's RAM your site is still going to be slower than a sick turtle.

At the same time you could be on a 1.8Ghz server with 512Mb RAM and sharing with 20 other people and if their sites aren't as processor intensive your site could still outperform the faster server. See? CPU and RAM tell you absolutely nothing about performance.

Performance is all about the average load that's placed on your server, the number of database queries that are being run, the traffic, bandwidth, etc and while you might think that a faster server would automatically be faster the chances are it won't because if a server is faster the host will likely allocate it extra users so they're not wasting resources.

To use your example, if a host had 200 users and they had a slow server and a fast server, the chances are they won't just put 100 users on each. They will try and balance the load, maybe putting 60 on the slow server and 140 on the fast to try and make both servers perform the same. Of course, the reality is a lot more complex.

The tools we use to judge performance are script execution time, server loads, etc. The CPU and RAM are only used to impress clients who don't know any better :p

ChronicleX.com
05-24-2005, 03:33 PM
Since I'm guessing that your CPU and RAM don't get upgraded that often and the viewers of your site wouldn't care couldn't you just ask your hosts what type of servers they have and ask for specs?

lol (To easy to just ask)

i like to look into new things and fetures php being one of them

plus some times i like to look at the hard way and see if i can make an easy way

i would like to see the script that SeeIT Solutions ask for tho

SeeIT Solutions
05-24-2005, 03:38 PM
I didn't say that these things don't affect the speed of the server - I said that these things along tell you absolutely nothing at all. You could be on a 4Ghz server with 8Gb RAM and sharing with only one other person but if that person is running processes which use all the CPU clock cycles and fill the server's RAM your site is still going to be slower than a sick turtle.

At the same time you could be on a 1.8Ghz server with 512Mb RAM and sharing with 20 other people and if their sites aren't as processor intensive your site could still outperform the faster server. See? CPU and RAM tell you absolutely nothing about performance.

Performance is all about the average load that's placed on your server, the number of database queries that are being run, the traffic, bandwidth, etc and while you might think that a faster server would automatically be faster the chances are it won't because if a server is faster the host will likely allocate it extra users so they're not wasting resources.

To use your example, if a host had 200 users and they had a slow server and a fast server, the chances are they won't just put 100 users on each. They will try and balance the load, maybe putting 60 on the slow server and 140 on the fast to try and make both servers perform the same. Of course, the reality is a lot more complex.

The tools we use to judge performance are script execution time, server loads, etc. The CPU and RAM are only used to impress clients who don't know any better :p

Now THAT was a great explanation...

ChronicleX.com
05-24-2005, 03:53 PM
not read it yet to long to read till i get home my boss is behind me :eek:

Velox Letum
05-24-2005, 07:11 PM
Is there anyway to show how long the server has been up in the last month? For example say

Server uptime in last 30 days = 29 days 20 hours 10 seconds (99.44%)

Thanks

Check out http://www.alertra.com. If your server is down, PHP won't be able to monitor it.

SeeIT Solutions
05-25-2005, 01:06 AM
I didn't want PHP to monitor it, I wanted PHP to display the result of something else that monitors it.

ChronicleX.com
05-31-2005, 11:36 AM
the first code worked for my paid hosting but i got my server ML350 server runing at home now with windows 2003 any body know how to do the server time for windows 2003? :confused: