Lim
Lim

Reputation: 33

how to autorun php file per day

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?

Upvotes: 1

Views: 451

Answers (3)

babak-maziar
babak-maziar

Reputation: 23

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

Upvotes: 0

Vijay Joshi
Vijay Joshi

Reputation: 959

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

Upvotes: 2

Justinas
Justinas

Reputation: 43441

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

Upvotes: 0

Related Questions