I am that geek who is working in the programming field, in love with poetry, always appreciate good lyrics and addicted to loud music.
[PHP + jQuery + ACD]: Checks For Server Status
I once wrote a tutorial about checking server availability, using PHP and jQuery. However, due to not-so-proper testing, I didn’t noticed that the script did not actually work. Cross domain problem slipped my mind.
So here, once again I’m writing on the same topic but this time not just PHP and jQuery. I’ll be using AJAX Cross Domain which allows you send messages or results to different domain. Main components you must have are
You might notice that ACD script is downloaded as text rather than javascript file. Make sure that you read and follow the installation guide, there are some settings need to be done.
We begin by editing the ACD javascript file. Add the URI you will call. For example in my case, it will be:
-
-
‘uri=(
-
http://blog.mohdrashidi.com/tutorials/activeServer/activeServer.php?url=blog.mohdrashidi.com
-
)’
-
Next is the same step, to write the PHP class (file name: activeServer.php):
-
-
< ?php
-
/**
-
* Created on 9 Mar 2008, 20:59:01
-
* @author Mohd Rashidi Bin Mohd Zin
-
*/
-
class ActiveServer
-
{
-
public function getServerStatus($hostname, $port=80)
-
{
-
if (!$fp)
-
{
-
return false;
-
}
-
return true;
-
}
-
}
-
-
$activeServer = new ActiveServer();
-
-
?>
Next is the Javascript. Different from previous tutorial, this script is much shorter and simpler (file name: activeServer.js):
-
-
$(document).ready(function() {
-
var status = ACD.responseText;
-
-
if (status == 1)
-
$("#content").html(‘Server is available’);
-
-
else
-
$("#content").html(‘Server is unavailable’);
-
});
Finally, the HTML code. Since we are using jQuery, there is no need to use events, such as onClick, onLoad, etc. All we need is to assign an id to a particular div:
-
-
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-
<html>
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-
<script type="text/javascript"
-
src="acd/acd.js?uri=(http://blog.mohdrashidi.com/tutorials/activeServer/activeServer.php?url=blog.mohdrashidi.com)"></script>
-
<script type="text/javascript" src="http://jquery.com/src/jquery-latest.pack.js"></script>
-
<script type="text/javascript" src="activeServer.js"></script>
-
<title>Active Server Demo</title>
-
</meta></head>
-
<body>
-
<div id="content"></div>
-
</body>
-
</html>
-
That’s all for this revisited tutorial. Happy coding
Possibly related posts (generated by Yet Another Related Posts Plugin):




Leave a Reply