How can I get a function executed in a php (cakephp) application at a specific point of time, without the intervention of a person clicking the link or triggering the function by himself/herself?
-
Use cron or whatever OS scheduling tool you have available.Matthew– Matthew2011-06-13 04:24:34 +00:00Commented Jun 13, 2011 at 4:24
-
possible duplicate of how to execute some function on specific time implicitly.mario– mario2011-06-13 04:25:18 +00:00Commented Jun 13, 2011 at 4:25
4 Answers
All other answers so far are right, you'll need to schedule a cron job (or scheduled task on Windows). With that said, CakePHP is designed to answer HTTP requests and not work through the command line.
For a tutorial specific to CakePHP, visit http://bakery.cakephp.org/articles/mathew_attlee/2006/12/05/calling-controller-actions-from-cron-and-the-command-line.
2 Comments
If you are on Linux or Mac, try Cron:
Comments
Two things:
For Linux:
https://www.interspire.com/support/kb/questions/298/How+do+I+set+up+CRON+on+my+server%3F
For Windows:
There is one more stuff, the above method are done on your server machine, but if you are expecting to do this from a page (browser), then you have to use AJAX + setTimeout you can get it done.
Comments
Yes using CRON as the scheduler and then using cakePHP shells to execute the code you need.
Here's the documentation from cakePHP 2.0: http://book.cakephp.org/2.0/en/console-and-shells.html