You can use the shell_exec
function in PHP to execute a command on the system and retrieve the output. On Linux systems, you can use the uptime
command to get the system uptime, which includes the time the system was booted.
Here's an example PHP code snippet that retrieves the system uptime and calculates the boot time in minutes:
main.php176 chars6 lines
The uptime
command with the -s
option returns the system boot time in ISO 8601 format. The strtotime
function converts the boot time string to a Unix timestamp, which represents the number of seconds since the Unix Epoch (January 1 1970 00:00:00 UTC). Finally, we calculate the number of minutes since the boot time by dividing the difference between the current time and the boot time by 60.
gistlibby LogSnag