Hello, everyone. I was working on a port checker. It is working fine, although it takes a while to load if the port is offline. I did add in a timeout on fsockopen. I am looking for a faster way to check them.
Code:
<?php
function check($ip, $port){
if(fsockopen($ip, $port,$errno, $errstr, 1))
{
echo '<span style="color:green;">Online</span>';
}else{
echo '<span style="color:red;">Offline</span>';
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet" type="text/css">
</head><body>
<div class="section">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 class="text-center">Servers</h1>
<p class="text-center lead">A subtitle.</p>
</div>
</div>
<div class="row">
<div class="col-md-3"><p>Google: </p><?php check('google.com',80); ?></div>
<div class="col-md-3"><p>FaceBook: </p><?php check('facebook.com',80); ?></div>
<div class="col-md-3"><p>YouTube: </p><?php check('youtube.com',80); ?></div>
<div class="col-md-3"><p>Twitter: </p><?php check('twitter.com',80); ?></div>
</div>
<br/>
<div class="row">
<div class="col-md-3"><p>Amazon: </p><?php check('amazon.com',80); ?></div>
<div class="col-md-3"><p>Wikipedia: </p><?php check('wikipedia.org',80); ?></div>
<div class="col-md-3"><p>Yahoo: </p><?php check('yahoo.com',80); ?></div>
<div class="col-md-3"><p>Bing: </p><?php check('bing.com',85); ?></div>
</div>
</div>
</div>
</body></html>
Last edited: