I am researching on how I can check to see if a specific hostname pointing to a database (presumably on port 3306) is reachable.
In php I am having a user fill out their database details, and with ajax I am running a script that pings the hostname provided but I can’t seem to get the results I want.
With my current script:
if (fsockopen($host, $port, $errno, $errstr, $timeout)) {
$return[$host]['message'] = "{$host} was reached";
$return[$host]['status'] = true;
} else {
$return[$host]['message'] = "{$host} is unreachable";
$return[$host]['status'] = false;
}
i get that the host is reachable, which in some of my test is true but in other its suppose to be false.
as my end result i want to tell the user that the hostname provided is incorrect, or unreachable.
Edit:
This is my ajax call for those interested.
$('#db_host').focusout(function () {
$.ajax({
url:'/json/auth/ping/' + $(this).val(),
dataType:'json',
success:function (data) {
if ($('#db_host').val() !== '') {
if (data.status === false) {
$('#db_host').qtip({
content:data.message,
position : {
my :'left center',
at :'right center'
},
effect:function () {
$(this).slideUp(500);
},
style : {
classes : 'ui-tooltip-red'
},
show : {
ready : true
}
});
}
}
}
});
});
You could try this way.