/    Sign up×
Community /Pin to ProfileBookmark

AJAX auto-refresh for simple PHP Page

Hello everyone

I have a very simple php page that uses shell_exec to get some basic stats for my LAMP. I currently have it setup to where it uses a javascript refresh every 60 seconds, but would like to setup AJAX to have it so it doesnt actually refresh the page. I am new to javascript/ajax so I am a little lost, here is my code

[CODE]<html>
<title> System Stats </title>
<head>
<script type=”text/JavaScript”>

function timedRefresh(timeoutPeriod) {
setTimeout(“location.reload(true);”,timeoutPeriod);
}

</script>
</head>

<body onload=”JavaScript:timedRefresh(60000);”>
<?php
/* Here I am setting up the variables for the commands to pass down through to the shell */
$top = (shell_exec(“top -b | head -n 25”));
$stats = (shell_exec(“iostat”));
$uptime = (shell_exec(“uptime”));
$disk = (shell_exec(“df -h”));
$lastlog = (shell_exec(“lastlog | grep -v ‘*'”));
$dmesg = (shell_exec(“dmesg | tail -n 25”));

/* Here I am outputting to the screen the commands I have specified above*/
echo “<BR><font color=green size=7> First 25 lines of top</font>n “;
echo “<pre><font color=black>$top</font></pre>”;

echo “<BR><font color=green size=7> Last 25 lines of dmesg</font>n “;
echo “<pre><font color=black>$dmesg</font></pre>”;

echo “<font color=green size=7>I/O stats</font>n”;
echo “<pre><font color=black>$stats</font></pre>”;

echo “<BR><font color=green size=7>Disk usage</font>n”;
echo “<pre><font color=black>$disk</font></pre>”;

echo “<BR><font color=green size=7> Last login info </font>n”;
echo “<pre><font color=black>$lastlog</font></pre>”;

echo “<BR><BR><BR>”;

?>

</body>
</html>
[/CODE]

I have been reading lots of blog/forums about this topic but I think I am just being overwhelmed with information. Any help would be appreciated. Thank!!!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DanInMAApr 08.2011 — I like to use a separate file for the php ( in my case asp) and use ajax to call an update to the included php file
Copy linkTweet thisAlerts:
@DanInMAApr 08.2011 — http://www.webdeveloper.com/forum/showthread.php?t=169337

this is an example, im sure there are simpler ways now, I use jquery for most of my ajax stuff
×

Success!

Help @fro1269 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...