LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Uptime posted to html via PHP? (https://www.linuxquestions.org/questions/linux-software-2/uptime-posted-to-html-via-php-23752/)

bkeating 06-19-2002 02:33 AM

Uptime posted to html via PHP?
 
Anyone know the command to post system uptime to a page?

Would like to post it on my front page. Isn't is like $PHP_Uptime er something? im looking but haven't found anything yet. Oh, except to echo end-users browser/os type :) neat stuff.

Shak 06-19-2002 06:30 AM

http://freshmeat.net/projects/phpuptime/?topic_id=862

reports the uptime, and makes it an image, you could edit the script

Shak

Mik 06-19-2002 10:28 AM

That's pretty nicely done. The only problem is it doesn't extract the number of days properly. The number of days doesn't always start on the 13th character. And it only reads 2 characters meaning you could never have an uptime greater then 99 days. But it shouldn't be too hard to modify that. You could remove the line $uptime = (exec("uptime"));
and replace the $up = line with the following one:

$up = (exec("uptime | sed 's/.*up //' | sed 's/ days.*//'"));

Haven't tried it out but something like that should work.

skeletal29 06-19-2002 04:11 PM

use phpsysinfo.

it will look like

http://skeletal29.homelinux.net/sysinfo/

bkeating 06-19-2002 05:46 PM

got it!


<?php
$fp = popen("/usr/bin/uptime", "r");
while($line = fgets($fp, 1024)):
printf("%s<br>\n", $line);
endwhile;
pclose($fp);
?>

works for me! but im interested in others :) thanks for the replies

Mik 06-20-2002 03:51 AM

Well since the output of uptime is just one line, and you want to display the whole line anyway. Why don't you change it to:

<?php
$up = exec("/usr/bin/uptime");
printf("%s<br>\n", $up);
?>


All times are GMT -5. The time now is 01:31 AM.