Reputation: 253
I want to schedule a php function to execute at a user's inputted scheduled time. Also my website is hosted in windows machine so I am looking for a windows based solution. I have made a function which looks like this:
function sendemail()
{
$cmd = 'schtasks /create /sc ONCE /tn emailtask /tr http://example.com/index.php/emailnotifications/sendemail';
exec ($cmd);
}
In the above code emailnotifications is my controller and sendemail is my function where I have written my code. Does anyone know a solution to create scheduled task in windows task schedular using php code?
Upvotes: 0
Views: 260
Reputation: 7935
I had such a requirement once (meaning the server was windows) and I used cronw with good results. The only change I suggest in your strategy is to call the script every minute and put all your schedules in a database table. Everytime the sendemail function is executed it will check if any emails are scheduled to go out at this time, it sends them and marks them processed. This approach is very scalable, so if you have millions of people scheduling emails, then you dont end up creating millions of scheduled tasks.
Upvotes: 1