הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   יש פעולה בPHP שמוציאה לפלט את הזמן שהדף בUPTIME? (https://hosts.co.il/forums/showthread.php?t=15290)

Alon.R 07-02-06 21:42

ציטוט:

נכתב במקור על ידי Israel-Serv.Net
יש איזה סקריפט שעובד בצורה אחרת ויכול להראות את הUPTIME בלי השימוש בפונקציה הזאת..
רק אני לא זוכר את השם שלו....
אם מישהו מכיר במקרה שיביא לו...

עריכה : אחלה :) ראיתי שמצאת

כן למי שמעוניין הינה הסקריפט:
PHP קוד:

<?php 
// format the uptime in case the browser doesn't support dhtml/javascript
// static uptime string
function format_uptime($seconds) {
  
$secs intval($seconds 60);
  
$mins intval($seconds 60 60);
  
$hours intval($seconds 3600 24);
  
$days intval($seconds 86400);
  
  if (
$days 0) {
    
$uptimeString .= $days;
    
$uptimeString .= (($days == 1) ? " יום" " ימים");
  }
  if (
$hours 0) {
    
$uptimeString .= (($days 0) ? ", " "") . $hours;
    
$uptimeString .= (($hours == 1) ? " שעה" " שעות");
  }
  if (
$mins 0) {
    
$uptimeString .= (($days || $hours 0) ? ", " "") . $mins;
    
$uptimeString .= (($mins == 1) ? " דקה" " דקות");
  }
  if (
$secs 0) {
    
$uptimeString .= (($days || $hours || $mins 0) ? ", " "") . $secs;
    
$uptimeString .= (($secs == 1) ? " שניה" " שניות");
  }
  return 
$uptimeString;
}

// read in the uptime (using exec)
$uptime exec("cat /proc/uptime");
$uptime split(" ",$uptime);
$uptimeSecs $uptime[0];

// get the static uptime
$staticUptime "השרת באוויר רצוף כבר: ".format_uptime($uptimeSecs);
?>
<script language="javascript">
<!--
var upSeconds=<?php echo $uptimeSecs?>;
function doUptime() {
var uptimeString = "השרת באוויר רצוף כבר: ";
var secs = parseInt(upSeconds % 60);
var mins = parseInt(upSeconds / 60 % 60);
var hours = parseInt(upSeconds / 3600 % 24);
var days = parseInt(upSeconds / 86400);
if (days > 0) {
  uptimeString += days;
  uptimeString += ((days == 1) ? " יום" : " ימים");
}
if (hours > 0) {
  uptimeString += ((days > 0) ? ", " : "") + hours;
  uptimeString += ((hours == 1) ? " שעה" : " שעות");
}
if (mins > 0) {
  uptimeString += ((days > 0 || hours > 0) ? ", " : "") + mins;
  uptimeString += ((mins == 1) ? " דקה" : " דקות");
}
if (secs > 0) {
  uptimeString += ((days > 0 || hours > 0 || mins > 0) ? ", " : "") + secs;
  uptimeString += ((secs == 1) ? " שניה" : " שניות");
}
var span_el = document.getElementById("uptime");
var replaceWith = document.createTextNode(uptimeString);
span_el.replaceChild(replaceWith, span_el.childNodes[0]);
upSeconds++;
setTimeout("doUptime()",1000);
}
// -->
</script>

ולהוסיף את הקוד הבא לאיפה שאתם רוצים שיהיה הפלט של הUPTIME:
HTML קוד:

<div id="uptime" class="btext"><?php echo $staticUptime; ?></div>
ועוד משהו קטן, להכניס לתוך תגית ה<body> את הגדרה הבאה:
HTML קוד:

onLoad="doUptime();"

Ori 07-02-06 21:45

אני מכיר גם שרות שמספק תמונה חיצונית שעושה את זה, אממ.. אני חושב שדניאל פרסם על זה אשכול.


כל הזמנים הם GMT +2. הזמן כעת הוא 03:50.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ