Hi, I have a WOL PHP script I am working on, and I was hoping to find a way to refresh part of the page using ajax, or if I should call an external php script?
My PHP script starts a pc and then checks multiple times to see if it is up and running… However, with PHP the user obviously has to wait until it is all the way done before it displays the results, I was hoping there was a way to make the “while loop” I am running run and update after the first part of the page has loaded?
Essentially, the checkstatus function checks to see if a port is running, then displays output… I was hoping to load the main page, then update the status of the portcheck using ajax, or another php script? Not sure how.
[php]
function CheckStatus($tries, $device, $deviceip, $deviceport, $devicemac1, $devicemac2, $maxtries, $broadcast, $udport, $timeout){
while($tries <= $maxtries){
echo “<br >”;
echo “Try $tries of $maxtries”;
echo “<br >”;
//echo portcheck($deviceip, $deviceport);
if (portcheck($deviceip, $deviceport) != 0){
echo " ------> Could NOT open connection to $device at $deviceip on port $deviceport";
echo “<br >”;
//echo "
TRIES: $tries";
}else{
echo "<br \>";
echo "<br \>";
echo "<br \>";
echo "TESTED OKAY! $device";
return TRUE;
}
$tries=$tries + 1;
}
echo "<br />";
echo "MAX TRIES REACHED... COULD NOT CONNECT!";
return FALSE;
}
include ‘db-connection.php’;
$button=$_GET[‘button’];
$sql = “SELECT * FROM devices WHERE id = ‘$button’”;
$result=mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
//$id= $row[‘id’];
$device= $row[‘device’];
$deviceip=long2ip($row[‘deviceip’]);
$deviceport=$row[‘deviceport’];
$devicemac1=$row[‘devicemac1’];
$devicemac2=$row[‘devicemac2’];
$maxtries=$row[‘maxtries’];
$broadcast=long2ip($row[‘broadcast’]);
$udport=$row[‘udport’];
$timeout=$row[‘timeout’];
}
mysql_close();
wakeonlan($device, $devicemac1);
$tries=1;
$maxtries=12;
//$deviceport=“22”;
echo “
”;
echo “
”;
echo “
”;
//echo “$device || $deviceip || $deviceport || $devicemac1 || $devicemac2 || $maxtries || $broadcast || $udport || $timeout”;
//echo “
”;
echo “Checking Status of Device:”;
echo CheckStatus($tries, $device, $deviceip, $deviceport, $devicemac1, $devicemac2, $maxtries, $broadcast, $udport, $timeout);
[/php]