I am trying to develop a result page in php where the results of a play(id, date, time, result)
will be published periodically after every 20 minutes. The result might come from File or Database. I did some R&D and found that cronjob
can be used. But, as I am using a host with no cronjob
support, I am trying to do it without cronjob
. also set_time_limit(0)
won't help as I am on a shared host.
cronjob is method which is performed by server not by client if you want to display result at client side all you need to do is use ajax function and call that function using set Interval javascript function.
Sample example is as below
function initialize()
{
$.ajax({
url : YOUR_URL,
data : DATAYOUWANNA_SEND,
dataType : "json"
beforeSend : function(){
//perform code before request made.
},
success : function(response){
//code after successful ajax response in either json or html according to dataType you set.
}
});
setInterval(function(){initialize()},3000);
}
and call this function on page load.
initialize()
Optionally you can do it with html Meta tag
<meta http-equiv="refresh" content="30">
It will refresh the page every 30 seconds.
You should use AJAX to get the latest record and inject them to the page with some javascript or jQuery.
Here's an example:
ajax.php
<?php
$result = SQL_RESULT;
echo json_encode($result);
?>
results.html
<script src="jquery.js"></script>
<script>
$(function(){
$.ajax({
url:'ajax.php',
dataType:'json',
success:function(data){
$.each(data,function(i){
$('<li/>').text(data[i].result).append('#ul');
});
}
});
});
</script>