שטח אחסון בשימוש / פנוי על השרת שלכם

תיאור:

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

first קוד:

  • מה: מודד נפח זכרון / שטח אחסון על השרת שלכם
  • איפה: בדף עצמו או בקובץ מצורף
<?php
class serverInfo{ 
	function Dbyte($Wert){ 
	  
	if ($Wert >= 1099511627776)	{ 
		$Wert = round($Wert / 1099511627776, 1) . " TB"; 
	} elseif ($Wert >= 1073741824) { 
		$Wert = round($Wert / 1073741824, 1) . " GB"; 
	} elseif ($Wert >= 1048576) { 
		$Wert = round($Wert / 1048576, 1) . " MB"; 
	} elseif ($Wert >= 1024) { 
		$Wert = round($Wert / 1024, 1) . " kB"; 
	} 
	else { 
		$Wert = round($Wert, 0) . " Bytes"; 
	} 

	return $Wert; 
	}  
	function Memory(){ 
			$mem = file_get_contents("/proc/meminfo"); 
			if (preg_match('/MemTotal\:\s+(\d+) kB/', $mem, $matches)) 
			{ 
				$total = $matches[1]; 
			} 
			unset($matches); 
			if (preg_match('/MemFree\:\s+(\d+) kB/', $mem, $matches)) 
			{ 
				$free = $matches[1]; 
			} 
			$free; 
			$total; 
			$usage = $total - $free; 
			$precent = 100 * $usage / $total; 
			return array( 
			"total" => $this->Dbyte($total*1024), 
			"free" => $this->Dbyte($free*1024), 
			"usage" => $this->Dbyte($usage*1024), 
			"precent" => round($precent,1), 
			); 
    } 
}
?>

second קוד:

  • מה: הדגמה של שימוש בפונקציה
  • איפה: בקובץ ובמיקום בו אתם רוצים להציג את המידע
// USAGE
$object 		=	new serverInfo();
$serverMemory	=	$object->Memory();

// GET ELEMENTS
echo '
	<ul>
		<li>סהכ זכרון: '.$serverMemory[total].'</li>
		<li>זכרון לא בשימוש: '.$serverMemory[free].'</li>
		<li>זכרון בשימוש: '.$serverMemory[usage].'</li>
		<li>זכרון חופשי באחוזים: '.$serverMemory[precent].'%</li>
	</ul>
';

סניפטים דומים: