To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-04-2003, 09:25 AM   #1
seby
Senior Member
 
Join Date: Nov 2002
Posts: 476
windows uptime

i had a few people ask me how can they get the uptime on windows to display it on a webpage like i do on my site on linux.

after doing some research i found its almost impossible unless you:

1) get some exe file from microsoft and execute it to get the uptime.
2) use the operating system pagefile that resets the time everytime the os is rebooted.

so after i found the location of the pagefile i came up with this script:

PHP Code:
<?php

$pagefile
= 'c:\pagefile.sys'; // Path to system pagefile. Default is c:\\pagefile.sys

function ifif ($value, $true, $false)
{
    if (
$value == 0)
    {
        return
$false;
    }
    else
    {
        return
$true;
    }
}

$upsince = filemtime($pagefile);
$gettime = (time() - filemtime($pagefile));
$days = floor($gettime / (24 * 3600));
$gettime = $gettime - ($days * (24 * 3600));
$hours = floor($gettime / (3600));
$gettime = $gettime - ($hours * (3600));
$minutes = floor($gettime / (60));
$gettime = $gettime - ($minutes * 60);
$seconds = $gettime;

$days   = ifif($days != 1, $days . ' days', $hours . ' day');
$hours   = ifif($hours != 1, $hours . ' hours', $hours . ' hour');
$minutes = ifif($minutes != 1, $minutes . ' minutes', $minutes . ' minute');
$seconds = ifif($seconds != 1, $seconds . ' seconds', $seconds . ' second');

echo
'Server uptime: ' . $days . ' ' . $hours . ' ' . $minutes . ' ' . $seconds;
echo
'<br /> Up since: ' . date('l. F jS, Y. h:i a', $upsince);

?>
its only been tested on windows 2000, and windows xp. It works on php 4.x.x, although i don't see why it shouldn't work on php 3.x

if you run a windows webserver, win95,98 i would like to know if it works on it. the system pagefile could possible be located elsewhere on these operating systems.

pagefile.sys is an invisible file, so you would have to search for it using the operating system search tool.

just change c:\ to the letter of your operating system.
__________________
Counter-Strike Planet
seby is offline   Reply With Quote
Old 11-04-2003, 11:33 AM   #2
Chrysanthus
Php freak
 
Chrysanthus's Avatar
 
Join Date: Mar 2003
Location: Sweden
Posts: 413
Thumbs up Wavo

!!That works fine i must say and the first code i ever sean to win GG!!

That's was just what i looking for and many other people to that i know of tha use Win...
__________________
Let the music play, it will be your getway..

The music is the way....



Chrysanthus is offline   Reply With Quote
Old 11-04-2003, 11:26 PM   #3
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,124
I found a wee Windows port of the Unix uptime program. Sorry, no link; but there are packages floating around out there with quite a few useful little utilities in them (like uptime, whois, gzip, make, uniq, grep and suchlike).
PHP Code:
<?php
echo `c:\\unix\\uptime`;
?>
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-05-2003, 12:36 PM   #4
piersk
Moderator
 
Join Date: Aug 2002
Location: Guildford, UK
Posts: 4,279
Thank goodness for phpsysinfo

(I know thats not much use if you're on windows, but... meh!)

Last edited by piersk; 11-05-2003 at 12:39 PM.
piersk is offline   Reply With Quote
Old 11-05-2003, 02:21 PM   #5
jayant
WARNING: I am watching u!
 
jayant's Avatar
 
Join Date: Aug 2002
Location: New Delhi, India
Posts: 891
Re: windows uptime

Quote:
Originally posted by seby


2) use the operating system pagefile that resets the time everytime the os is rebooted.

Neat
__________________
Jayant Kumar Gandhi
Computer Help | GZip/ Page Compression Test | My pic/ How I look?
Marking the thread as 'resolved' is more important than saying "thanks. that solved it"
Click "Mark Thread Resolved" in the thread tools and the top of the thread.
Keep sensible thread titles.
jayant is offline   Reply With Quote
Old 11-15-2003, 12:03 AM   #6
Chrysanthus
Php freak
 
Chrysanthus's Avatar
 
Join Date: Mar 2003
Location: Sweden
Posts: 413
Hi you forgott this...

PHP Code:

$days   
= ifif($days != 1, $days . ' days', $hours . ' day');

shoulde be this or the times get wrong i think!

$days   = ifif($days != 1, $days . ' days', $days . ' day');
__________________
Let the music play, it will be your getway..

The music is the way....



Chrysanthus is offline   Reply With Quote
Old 11-15-2003, 01:23 AM   #7
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,124
the function ifif() is just a reimplementation of the ?: operator...
PHP Code:
$hours   = ($hours != 1) ? $hours . ' hours' : $hours . ' hour';
or even
PHP Code:
$hours   = $hours.(($hours != 1) ?  ' hours' :  ' hour');
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 11-24-2003, 12:39 PM   #8
KITTfan2K
Farscape Rules!
 
KITTfan2K's Avatar
 
Join Date: Oct 2002
Location: Uncharted Territories
Posts: 119
Re: Re: windows uptime

Quote:
Originally posted by jayant
Neat
That wouldn't work on my system, because I have disabled the pagefile.

I don't need it. Windows (98) is stable enough when it's only got 256 mb RAM to play with, and no virtual RAM.

KITTfan2K
KITTfan2K is offline   Reply With Quote
Old 11-30-2003, 06:37 PM   #9
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
you obviously dont do much with a computer........
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 12-01-2003, 01:36 AM   #10
jayant
WARNING: I am watching u!
 
jayant's Avatar
 
Join Date: Aug 2002
Location: New Delhi, India
Posts: 891
I have 512MB RAM on my Win98 and I still use about 1gigs of virtual memory for those 3D apps (3DS MAX, Bryce, ...) etc.
__________________
Jayant Kumar Gandhi
Computer Help | GZip/ Page Compression Test | My pic/ How I look?
Marking the thread as 'resolved' is more important than saying "thanks. that solved it"
Click "Mark Thread Resolved" in the thread tools and the top of the thread.
Keep sensible thread titles.
jayant is offline   Reply With Quote
Old 12-07-2003, 09:34 PM   #11
seby
Senior Member
 
Join Date: Nov 2002
Posts: 476
diabling the pagefile is not a very good idea.
hell, i have 2gb of ram and my virtual memory is 3.5Gb.
__________________
Counter-Strike Planet
seby is offline   Reply With Quote
Old 12-08-2003, 07:35 AM   #12
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
disabling the page file makes sense from a securiy point of view.

Example: The user enters data. You encrypt this data. If that data is only stored in ram the user can easily overwrite the nonencrypted data with the encrypted data and remove all traces of the data from ram this way. However if you're using virtual memory then the data could have been written to the disk and the programmer has no control over when that gets changed.
drawmack is offline   Reply With Quote
Old 09-17-2005, 05:18 PM   #13
shanee86
Junior Member
 
Join Date: Sep 2005
Posts: 2
Hi am I new here but thanks I found this very very helpfull I found it searching google. I have to say I run a server from my house on windows and wanted something like phpsysinfo for my server. And this didn't work at first lol. Because I made a partion only for my paging file on my 200 gig storage drive and had none on c thought it would speed it up since it wasn't loading from c when all the other things were seems it did. But when I first ran the script it say my pc had been up for like 123 days plus or something since like 1942 lol. I don't know how it got that but I added paging file to c and it worked thanks. If my paging file is on say K can I change it to that?
shanee86 is offline   Reply With Quote
Old 09-17-2005, 05:29 PM   #14
shanee86
Junior Member
 
Join Date: Sep 2005
Posts: 2
Oh one more thing can someone add cpu usage thing to it I want know my cpu usage via web? I have no idea how I am learning php though thanks.
shanee86 is offline   Reply With Quote
Old 07-15-2006, 11:55 PM   #15
cylim
Junior Member
 
Join Date: Jan 2006
Posts: 1
Fix some errors
//----- Uptime ------
$pagefile = 'c:\pagefile.sys'; // Path to system pagefile. Default is c:\\pagefile.sys

function ifif ($value, $true, $false)
{
if ($value < 2)
{
return $false;
}
else
{
return $true;
}
}

$upsince = filemtime($pagefile);
$gettime = (time() - filemtime($pagefile));
$days = floor($gettime / (24 * 3600));
$gettime = $gettime - ($days * (24 * 3600));
$hours = floor($gettime / (3600));
$gettime = $gettime - ($hours * (3600));
$minutes = floor($gettime / (60));
$gettime = $gettime - ($minutes * 60);
$seconds = $gettime;



$days = ifif($days , $days . ' days', $days . ' day');

$hours = ifif($hours , $hours . ' hours', $hours . ' hour');
$minutes = ifif($minutes , $minutes . ' minutes', $minutes . ' minute');
$seconds = ifif($seconds , $seconds . ' seconds', $seconds . ' second');
cylim is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 08:11 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.