4

I have an issue with shell_exec() on certain hosts, by default it's disabled on certain web hosts. I'm looking at running the same script without using shell_exec.

I'm looking for an alternative way to get the same result, any help would be appreciated.

$uptime = shell_exec("cut -d. -f1 /proc/uptime");
$days = floor($uptime/60/60/24);
$hours = $uptime/60/60%24;
$mins = $uptime/60%60;
$secs = $uptime%60;
echo "<div><hr><strong>Uptime</strong>: this server is up $days days $hours hours $mins minutes and $secs seconds</div>";
  • You could have a variable in your database for the first recorded time, that you'd use to compute uptime. For each request check if that this variable is null and set it to current time if it's the case. It's so dirty it's a crime and it adds a db call for each request :) – A wild elephant Sep 28 '15 at 08:46
  • 1
    possible duplicate of [How to get CPU usage and RAM usage without exec?](http://stackoverflow.com/questions/4705759/how-to-get-cpu-usage-and-ram-usage-without-exec) – James McClelland Sep 28 '15 at 12:32
  • @JammyDodger231 Given how the question is formulated I'd say no. Seems like the author want a general alternative to shell_exec, not just for the example he provides. – A wild elephant Sep 28 '15 at 12:37
  • 1
    I had thought that based on the question title but it was when I saw "I'm looking for an alternative way to get the same result" so I thought it was only for that instance – James McClelland Sep 28 '15 at 12:42

1 Answers1

0

This answer to another SO question should help you out. It suggests phpSysinfo / Linfo, open source scripts that seem to read directly from /proc to get system information, notably uptime. It should work unless the open_basedir restriction is in effect, as mentioned in the comments.

Don't hesitate to upvote the original answer if it helped you.

Community
  • 1
  • 1