0

How can I run a .php file every x minutes/hours/days/years/whatever?

I have windows XP OS (and so does my host) so if I remember correctly I won't be able to use 'cron'.

I thought of using header("refresh:120; url=myscript.php"); to check if x time has passed since the last script's execution, and if true then run it again. I could then leave my pc on the page(which would probably be something like /hiddenpage.php).

I could do the same without leaving my pc on 24/7, instead I could do the check every time an user loads a page, but that's an unsure method.

Or, set a timer on the web page(s) with a countdown until the next execution of script (using javascript/whatever) and then reload the page (or directly run the script), though I'd have to use my pc for this.

So, any tips?

  • 4
    Windows has task scheduler in place of cron. See if you can use this. – Mchl May 09 '14 at 15:56
  • You can get a cron version for windows (http://cronw.sourceforge.net/) but your host would need to install it for you. I would refrain from dodgy methods like leaving browser open to do the work. – Mattt May 09 '14 at 15:58
  • http://stackoverflow.com/questions/295386/how-to-run-a-php-file-in-a-scheduled-task-windows-task-scheduler – MonkeyZeus May 09 '14 at 16:01
  • You could use www.cronjob.de – JPJens May 09 '14 at 16:02

2 Answers2

3

Set up a batch (.bat) file to run your php script. The batch file will be something like:

C:\PHP\php.exe -f C:\myphpfile.php

Then have the windows task scheduler run the batch file at whatever interval you wish.

rrtx2000
  • 616
  • 4
  • 12
0

you can write file.js with ajax you can call a localhost/file.php

note : if you are intersted I can write a code.

Mimouni
  • 3,427
  • 3
  • 24
  • 32