473,750 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server Reboot

Is there a way (through a variable) to show the date of the last server
reboot i.e. when PHP last started running? As I am trying to show the
server uptime, which of course only works from the last reboot,
therefore my %ages are very low.

Cheers,
Ben
Jul 17 '05 #1
8 4454
Ben Allen wrote:
Is there a way (through a variable) to show the date of the last server
reboot i.e. when PHP last started running? As I am trying to show the
server uptime, which of course only works from the last reboot,
therefore my %ages are very low.

You could use /proc/uptime to retrieve it.
For a php example, check this out:

http://www.xenocafe.com/tutorials/ph...time/index.php

--
http://www.phpforums.nl
Jul 17 '05 #2
Peter van Schie wrote:
You could use /proc/uptime to retrieve it.
For a php example, check this out:

http://www.xenocafe.com/tutorials/ph...time/index.php


I just noticed that that tutorial has a lot of unnecessary mumbo jumbo
in it.
Here's a simpler code snippet of how to use /proc/uptime:

<?php
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime / 60 / 60 / 24);
$hours = $uptime / 60 / 60 % 24;
$mins = $uptime / 60 % 60;
$secs = $uptime % 60;
echo 'Uptime is: ' . $days . ' days ' . $hours . ' hours ' . $mins
minutes . ' and ' . $secs . ' seconds';
?>

--
http://www.phpforums.nl
Jul 17 '05 #3
Peter van Schie wrote:
Peter van Schie wrote:
You could use /proc/uptime to retrieve it.
For a php example, check this out:

http://www.xenocafe.com/tutorials/ph...time/index.php


I just noticed that that tutorial has a lot of unnecessary mumbo jumbo
in it.
Here's a simpler code snippet of how to use /proc/uptime:

<?php
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime / 60 / 60 / 24);
$hours = $uptime / 60 / 60 % 24;
$mins = $uptime / 60 % 60;
$secs = $uptime % 60;
echo 'Uptime is: ' . $days . ' days ' . $hours . ' hours ' . $mins
minutes . ' and ' . $secs . ' seconds';
?>

Thanks, that code (with a few tweaks involving the minutes text-oops)
gives me:
Uptime is: 5 days 21 hours 34 minutes and 44 seconds

which is the same as what my other script was giving me and is the
uptime since the last reboot. Obviously this posses problems when trying
to calculate a percentage.

Thanks
Ben
Jul 17 '05 #4
Ben Allen wrote:
Thanks, that code (with a few tweaks involving the minutes text-oops)
gives me:
Uptime is: 5 days 21 hours 34 minutes and 44 seconds

which is the same as what my other script was giving me and is the
uptime since the last reboot. Obviously this posses problems when trying
to calculate a percentage.


Sorry I must have misinterpreted your question then. What percentage are
you trying to calculate?
--
http://www.phpforums.nl
Jul 17 '05 #5
>> <?php
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime / 60 / 60 / 24);
$hours = $uptime / 60 / 60 % 24;
$mins = $uptime / 60 % 60;
$secs = $uptime % 60;
echo 'Uptime is: ' . $days . ' days ' . $hours . ' hours ' . $mins
minutes . ' and ' . $secs . ' seconds';
?>
Thanks, that code (with a few tweaks involving the minutes text-oops)
gives me:
Uptime is: 5 days 21 hours 34 minutes and 44 seconds

which is the same as what my other script was giving me and is the
uptime since the last reboot.


If you want the uptime in just seconds, $uptime in the above
script gives you that.
Obviously this posses problems when trying
to calculate a percentage.


What percentage? What problems? Since you haven't said what you
want, nothing is obvious.

Gordon L. Burditt
Jul 17 '05 #6
Gordon Burditt wrote:
<?php
$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime / 60 / 60 / 24);
$hours = $uptime / 60 / 60 % 24;
$mins = $uptime / 60 % 60;
$secs = $uptime % 60;
echo 'Uptime is: ' . $days . ' days ' . $hours . ' hours ' . $mins
minutes . ' and ' . $secs . ' seconds';
?>

Thanks, that code (with a few tweaks involving the minutes text-oops)
gives me:
Uptime is: 5 days 21 hours 34 minutes and 44 seconds

which is the same as what my other script was giving me and is the
uptime since the last reboot.

If you want the uptime in just seconds, $uptime in the above
script gives you that.

Obviously this posses problems when trying
to calculate a percentage.

What percentage? What problems? Since you haven't said what you
want, nothing is obvious.

Gordon L. Burditt


Sorry, basically, I wanted to calculate uptime as a percentage
(preferably over the year), however, I then found the $uptime variable
only counted since the last reboot, therefore I wanted to show when the
server was last rebooted and also divide uptime by the server reboot
time. This is the code i was using, please note, i have added variables
into the 'start date' so I can set the reboot date manually. I wondered
if there was a way to do this manually.

<?php
$uptime = @exec('uptime') ;
preg_match("/averages?:
([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs );
$uptime = explode(' up ', $uptime);
$uptime = explode(',', $uptime[1]);
$uptime = $uptime[0].', '.$uptime[1];
$sday = 12;
$smonth = 07;
$syear = 2005;
$start=mktime(0 , 0, 0, $smonth, $sday, $syear, 0);
$end=mktime(0, 0, 0, date("m"), date("d"), date("Y"), 0);
$diff=$end-$start;
$days=$diff/86400;
$percentage= round(($uptime/$days) * 100, 2);
#$load=$avgs[1].",".$avgs[2].",".$avgs[3]."";
$page='<style type="text/css">
<!--
..style1 {
color: #000000;
font-weight: bold;
}
..style2 {font-size: 12px}
-->
</style>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0"
style="border: 1 solid #000000">
<tr>
<td width="150" bgcolor="#F4F4F 4" style="border: 1 solid
#000000"><div align="center"> <span class="style1"> <b>U</b>ptime:
<strong>'.$upti me.'</strong></span><br>
</div></td>
</tr>
<tr>
<td width="150" bgcolor="#F4F4F 4" style="border: 1 solid
#000000"><div align="center">
<p><span
class="style1"> <strong>'.$perc entage.'%</strong></span><strong><b r>
</strong>(since last reboot)</p>
</div></td>
</tr>
<tr>
<td width="150" bgcolor="#F4F4F 4" style="border: 1 solid
#000000"><div align="center"> <span class="style2"> Server Last Rebooted
on 12/07/2005 </span></div></td>
</tr>
</table>
</body>';
echo $page;
?>
Jul 18 '05 #7
Ben Allen wrote:
Sorry, basically, I wanted to calculate uptime as a percentage
(preferably over the year), however, I then found the $uptime variable
only counted since the last reboot, therefore I wanted to show when the
server was last rebooted and also divide uptime by the server reboot
time. This is the code i was using, please note, i have added variables
into the 'start date' so I can set the reboot date manually. I wondered
if there was a way to do this manually.


I don't think that's possible, because to calculate that you'd need to
know for how long the server has been down before the last reboot.
I can't think of any file/device to retrieve that on a Linux box, I
might be wrong though.
--
http://www.phpforums.nl
Jul 18 '05 #8
Ben,

Won't work.

All you can determine is how long the machine has been up since the last reboot.
You can't tell how long it was down.

I see two ways around it. Either append the current date and time to a file
every minute (depending on the accuracy you want) and parse the file to find the
missing times, or monitor the site from a remote system.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15227
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
19
14848
by: Thue Tuxen Sørensen | last post by:
Hi everybody ! I´m maintaining a large intranet (approx 10000 concurrent users) running on one IIS box and one DB box with sqlserver 2000. Currently there is 2,5 GB Ram, 1 1400 mhz cpu and 2 scsi disks installed on the db box. Sqlserver is set to use max 1,4 GB RAM, and the sqlserver does not seem to be using it all.
10
7295
by: JL | last post by:
To All, I have a SQL2KSP3a database(<1GB) running on a 4x3GB physical CPU with 4GB of ram. It is Windows Server 2003 with hyper-threading turn on. There are ~420 .Net users/cxns (fat client, no web/app servers) with connection pooling and ~1 trx/sec. The database growth is neglegeable and actually is not even relevent which I will explain in a minute. 99% of the trxs are from one SP that does a select. The resultsets are relatively...
2
2150
by: Tim Nelson | last post by:
I created a simple C# .Net application to prove I can deploy it on a Win2k server running terminal services. I installed the 1.1 .Net Framework and installed the application (using a VS Setup app) on the machine. It runs perfectly when I log in as Administrator but generates an exception when I run it as any other user. Do I need a reboot or something after installing the framework? Do I need to tweak something in the .Net framework...
1
3158
by: Keith | last post by:
All, I have been told this is an ASP.NET issue and not an IIS issue, so I am posting this here. I have a problem with ASP.NET returning an HTTP 500 error when trying to run ASPX pages on Windows Server 2003 Enterprise Edition Only. This works on Windows 2000, Windows 2003 Web Edition and
0
5651
by: jsausten | last post by:
I am having this ridiculously frustrating problem, migrating an existing web app to VS.2005. Initially I was able to successfully convert my VS 2002 app, by opening the Localhost site using the new 'Local IIS' option (File -> Add Existing Web Site ->. Local IIS -> Select the Localhost site) and everything was OK. However, when I shut down and reboot, I was unable to open the same project and got the following error: "Unable to open...
3
1537
by: dm1608 | last post by:
I have an Ecommerce application that uses mostly ASP and a bit of ASP.NET. Monitoring the servers memory via SNMP every 5 minutes would indicate that there is a memory leak somewhere within the application. Of course, the vendor says its a "Microsoft IIS" issue and tells us to reboot the server each day or kill the worker process for IIS. We're currently rebooting our server at 4 AM each night. This is a really lame idea, in my...
5
2335
by: war_wheelan | last post by:
I created the db with the attached script and I am able to access it until I reboot the server. I've tried enabling flag 1807 via the SQL server service and the startup parameters of the instance. In all cases the database always come up suspect after a reboot. There was one instance where I was able to recover, but I am not sure how that happened. Does anyone have an idea of how I can reboot the server without the database becomming...
3
6442
by: Steve | last post by:
Hi All I downloaded Sql server 2005 express SP2 and attempted to modify the Bootstrapper package files as I did with SP1 When i try to install SQL server as part of my VS 2005 deployment app I get an error at the end of the SQL server install phase 'Invalid endpoint'. (Note SQL server express gets installed OK) If I run SQL server express SP2 setup directly it I don't get the error
0
9000
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4713
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.