0

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?

2
  • What about it the schedule is in anohter machine and you do an wget of the php script? Commented Oct 16, 2012 at 10:22
  • no both are in the same machine Commented Oct 16, 2012 at 10:25

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for the response. Yes will surely go through cronw and will let you know if I am getting expected result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.