-1

I am stuck on this scenario where I want a page to auto refresh every 10 seconds. I have used

header("refresh: 10;");

which does work when I access the URL through my browser, but i want it to run in background. I have used Cron to access the url once and then it should refresh the page every 10 seconds. But this doesn't work.. can anyone please tell me the solution to this ??

timbmg
  • 3,192
  • 7
  • 34
  • 52
Babar Ali
  • 181
  • 1
  • 18
  • Possible duplicate of [Javascript function to reload a page every X seconds?](http://stackoverflow.com/questions/3992353/javascript-function-to-reload-a-page-every-x-seconds) – timbmg Dec 05 '15 at 14:13

2 Answers2

4
<meta http-equiv="refresh" content="10; URL=http://www.domain.com/">

or just

<meta http-equiv="refresh" content="10">

or try this in a script

setTimeout(function(){
  window.location.reload(1);
}, 10000);
Andy
  • 397
  • 2
  • 8
  • thanku ... will this work even if browser is closed ?? – Babar Ali Dec 05 '15 at 14:14
  • No it won't. Then I think you need to explain a little more what you are trying to achive – Andy Dec 05 '15 at 14:16
  • It would not. All of these solutions are only for when a user visits the page. If you want it to run automatically, you need a CRON-job, which can only be run every 1 minute. – Qirel Dec 05 '15 at 14:17
  • What should be updated if the page is closed? I think what you need is to run a cron job instead. Can you please explain what you want to do? – Andy Dec 05 '15 at 14:19
  • i want to run my php code to fetch data from twitter api. Now i cannot keep the browser 24/7 to refresh it every 10 seconds. I want the process to run in background./ Although cronjob works great but it only allows me to run proccess every 1 minute... i need to run script every 10 seconds. – Babar Ali Dec 05 '15 at 14:22
  • It's not possible refresh a page that's not open so then I think you need to look at something like [this](http://serverfault.com/a/246046) Another alternative is to set a infinite loop in php and use sleep() – Andy Dec 05 '15 at 14:27
0

Try this code put it in head of html page

< meta http-equiv="refresh" content="5" >