I was trying to ping a target like 10 times after the user clicks the button with a small amount of delay.
I could do it with a for loop, but the problem is that the document would freeze while it does executes everything in the document, and I want to echo it out as each ping is done.
I've tried multiple methods now and ran into problems everytime. I guess the best solution would be to use ajax and then loop it within the javascript, or maybe just execute the code several times. I've not however been able to figure out how to do it.
This is what the function looks like.
function ping($host, $port, $timeout) {
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms";
}
And I use this to call the function in PHP.
echo ping($website, 80, 10);
So, I basicly added it to the document where the function is located.
Now, I've been trying to figuring out how to load this for a while, and it hasn't gone to great. Would love any help with this.
How do I load and use this function without freezing the document completely untill it is done?