How to use file_get_contents on loop? <p>I'm trying to use file_get_contents on loop, in order to fetch JSON string from an URL continuously (every second). And i need to store the result into a javascript variable. Here was my approach, but i didn't get any result from this. My page showed me nothing but endless loading.</p> <pre><code>&lt;?php set_time_limit(0); while(true) { $jsonContent=file_get_contents('http://megarkarsa.com/gpsjson.php'); echo $jsonContent; sleep(10); } ?&gt; </code></pre> <p>And here my javascript code.</p> <pre><code>setInterval(function(){ var jsonUpdPostData = &lt;?php echo $jsonContent; ?&gt;; }, 100); </code></pre> <p>What should i do to make it work? Any suggestion will be appreciated.</p>