The website is written in .php with the connection of MySQL
I had a file that's named PMautoemail.php
It can be run successfully but I only want it to run once a day. Cronjob couldn't be set up as I am running in a windows server and this website will be run by other people too. What should I do?
Asked
Active
Viewed 370 times
1

Lim
- 39
- 8
-
[Setting Up A Cronjob In Windows Xampp](https://stackoverflow.com/questions/17442040/setting-up-a-cronjob-in-windows-xampp) – Alive to die - Anant Feb 17 '20 at 08:14
-
@Lim, Check here https://stackoverflow.com/questions/33932617/how-can-i-run-a-php-script-automatically-daily-in-wamp-windows-environment – Rahul Kr Daman Feb 17 '20 at 08:31
3 Answers
2
You can use Windows Task Scheduler to run the file daily. Think of it as cronjob for Windows.
EDIT:
Another option: Windows Sub-system for Linux. https://learn.microsoft.com/en-us/windows/wsl/install-win10

Alive to die - Anant
- 70,531
- 10
- 51
- 98

Vijay Joshi
- 919
- 7
- 17
-
Other than Windows Task Scheduler? Is there any other way than that, because it's not what I wanted. – Lim Feb 17 '20 at 08:25
-
There is one other option:Windows Subsystem for Linux. https://learn.microsoft.com/en-us/windows/wsl/install-win10. Using it you can run cronjobs like linux. – Vijay Joshi Feb 17 '20 at 08:27
-
I just found out that I will be using iPage to display the website, will the webside auto run the file in the domain? – Lim Feb 18 '20 at 07:23
0
Well, if you can't use CronJob, you can always start file in background and set some sleep. It's not proper solution, but sometimes be only option in some cases:
// init_linux.php
exec('php my_cron.php &');
// init_win.php
pclose(popen("start /B php my_cron.php", "r"));
// my_cron.php
// [... do some stuff ...];
sleep(60 * 60 * 24); // sleep for 1 day

Justinas
- 41,402
- 5
- 66
- 96
0
You can save the date and time of the script execution in the database. Then at the beginning of your code, check if the script has been run today. Stop the script if it is running today

babak-maziar
- 23
- 7