user3569990
user3569990

Reputation: 9

Run a php script every x minutes (no cron)

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?

Upvotes: 0

Views: 394

Answers (2)

Mimouni
Mimouni

Reputation: 3630

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

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

Upvotes: 0

rrtx2000
rrtx2000

Reputation: 636

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.

Upvotes: 3

Related Questions