Reputation: 199
got this code:
<?php
function test ($url){
$starttime = microtime(true);
$valid = @fsockopen($url, 80, $errno, $errstr, 30);
$stoptime = microtime(true);
echo (round(($stoptime-$starttime)*1000)).' ms.';
if (!$valid) {
echo "Status - Failure";
} else {
echo "Status - Success";
}
}
test('google.com');
?>
i want to use something like this:
<script>
setInterval(function(){<?php test('google.com'); ?>},3000);
</script>
How di i call php function 'test' with setInterval?
Upvotes: 0
Views: 1983
Reputation: 10030
You can send AJAX request to the server to execute that script after x seconds.
var milliSeconds = 1000; // <-- As an example
setInterval( function() {
// <-- Your AJAX request here
}, milliSeconds);
Upvotes: 1