get system uptime in php

To get the system uptime in PHP, you can use the exec() function to execute the uptime command and retrieve the output. Here's an example code block that shows how to do it:

main.php
<?php
// Execute the uptime command and retrieve the output
$uptime = exec('uptime');

// Echo the output
echo $uptime;
?>
123 chars
8 lines

When you run this code, you'll see the system uptime displayed in the format 10:23 up 23 days, 23:45, 1 user, load average: 0.89, 1.05, 1.02. The uptime value will be located after the up keyword.

related categories

gistlibby LogSnag