-1

I have a Windows VPS and a website with an administration for a game. I wish that in my administration I can recover the use of the CPU in % as well as the use of RAM and that values ​​update when the values ​​change.

Is that possible?

3
  • do you mean how much ram/cpu php is using? Commented Aug 7, 2017 at 15:19
  • I would like to recover the CPU and RAM usage of my VPS to see the performance since the site administration Commented Aug 7, 2017 at 15:22
  • 1
    Asking whether or not something is possible is not really a good question, as the answer is either 'Yes', or 'No'. If you already have some related code or an attempt to solve this, then you should include it in your question and point out specifically where you are having trouble. If you have not yet made an attempt, then you should do so before asking your question. Commented Aug 7, 2017 at 15:24

2 Answers 2

1

if you mean how much ram/cpu php is using then you can do the following using plain php without using any package: this returns the ram usage:

function get_server_memory_usage(){

$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem);
$mem = array_merge($mem);
$memory_usage = $mem[2]/$mem[1]*100;
return $memory_usage;
}

cpu usage:

function get_server_cpu_usage(){
$load = sys_getloadavg();
return $load[0];
}
Sign up to request clarification or add additional context in comments.

How 'safe' is this?
1

You can use PHPSYSINFO. The links are below. It is a php script, just upload it to your server folder and make the required configuration.

Link: http://phpsysinfo.github.io/phpsysinfo/ and https://github.com/phpsysinfo/phpsysinfo

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.