php - How to use file_get_contents on loop? -


i'm trying use file_get_contents on loop, in order fetch json string url continuously (every second). , need store result javascript variable. here approach, didn't result this. page showed me nothing endless loading.

<?php     set_time_limit(0);     while(true)     {     $jsoncontent=file_get_contents('http://megarkarsa.com/gpsjson.php');     echo $jsoncontent;     sleep(10);     }  ?> 

and here javascript code.

setinterval(function(){         var jsonupdpostdata = <?php echo $jsoncontent; ?>; }, 100); 

what should make work? suggestion appreciated.

you can make work way:

getcontent.php

<?php echo file_get_contents('http://megarkarsa.com/gpsjson.php'); 

xxxx.js

setinterval(function(){   var xmlhttp = new xmlhttprequest();    xmlhttp.onreadystatechange = function() {     if (xmlhttp.readystate == 4) {       alert(xmlhttp.responsetext); // contains new file contents     }   }    xmlhttp.open('get', 'getcontent.php');   xmlhttp.send(); }, 100); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -