1

I want to rerun a php function on a timer so it runs every x ammount of time then when it runs again i want to update the page with the new value without reloading (useing ajax i think)

function get_usedram($arg) {


  if ($arg == kb) {
    $totalram = get_totalram(kb);
    $freeram = get_freeram(kb);
    $sum = $totalram - $freeram;
    return $sum . ' ' . 'KB';
  }

  else if ($arg == mb) {
    $totalram = get_totalram(mb);
    $freeram = get_freeram(mb);
    $sum = $totalram - $freeram;
    return $sum . ' ' . 'MB';

  }

  else if ($arg == gb) {
    $totalram = get_totalram(gb);
    $freeram = get_freeram(gb);
    $sum = $totalram - $freeram;
    return $sum . ' ' . 'GB';
  }

}

This is my function it pulls in two other function to get the ammount of RAm being used by the server i want to run this every 5 seconds for example then update the value i have on screen im useing it like this:

echo get_usedram(gb) . ' ' . 'Ram Being Used';

Thanks!

Tom Rouse
  • 51
  • 9
  • You can run a PHP script every x amount of time using [Cron](http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php). Then on your page you can send an ajax request every 5 seconds to get current data – kscherrer Jan 24 '17 at 16:44

0 Answers0