<?php
// File to store the server load data
$logFile = "server_load.log";
// Function to get server load average
function getServerLoad() {
if (function_exists('sys_getloadavg')) {
return sys_getloadavg();
}
return [0, 0, 0]; // Default if sys_getloadavg is not available
}
// Get the server load
$load = getServerLoad();
// Prepare the log entry
$logEntry = sprintf(
"[%s] Load Averages: 1 min: %.2f, 5 min: %.2f, 15 min: %.2f\n",
date('Y-m-d H:i:s'),
$load[0],
$load[1],
$load[2]
);
// Write the log entry to the file
file_put_contents($logFile, $logEntry, FILE_APPEND);
?>