I wrote a simple php script to output the RAM utilization on my server to an HTML page. However when I open the web page I see the php code instead of the expected output.
HTML Document
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Character set encoding -->
<meta charset="UTF-8" />
<!-- Jquery JS files -->
<script src="js/jquery/jquery-1.11.3.min.js"></script>
<script src="js/jquery/jquery-2.1.4.min.js"></script>
<script src="js/jquery/jquery-ui-1.11.4.min.js"></script>
<!-- AJAX -->
<script src="ajax.js"></script>
</head>
<body>
<div id="statistics">
<h1>Memory</h1>
<table>
<tr><th>Total</th><th>Free</th><th>Used</th></tr>
<tr id="mem"><script>memDoc()</script></tr>
</table>
</div>
</body>
</html>
AJAX Document
function memDoc() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById('mem').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "free.php", true);
xmlhttp.send();
}
setInterval(function() {
memDoc()
}, 5000);
PHP Document
<?php
$totalMem = exec("free -m | awk '{print $2}' | awk '(NR==2)'");
$freeMem = exec("free -m | awk '{print $4}' | awk '(NR==2)'");
$usedMem = exec("free -m | awk '{print $3}' | awk '(NR==2)'");
echo "<td>" . $totalMem . "</td><td>" . $freeMem . "</td><td>" . $usedMem . "</td>";
?>
I am running Ubuntu Server 15.04 with apache2 (2.4.10-9ubuntu1) and php5 (5.4.6+dfsg-4ubuntu6)
Aucun commentaire:
Enregistrer un commentaire