3

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?

TuteC
  • 4,342
  • 30
  • 40
pushpa
  • 573
  • 2
  • 7
  • 19
  • Use cron or whatever OS scheduling tool you have available. – Matthew Jun 13 '11 at 04:24
  • possible duplicate of [how to execute some function on specific time implicitly.](http://stackoverflow.com/questions/5220561/how-to-execute-some-function-on-specific-time-implicitly) – mario Jun 13 '11 at 04:25

4 Answers4

4

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.

Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
  • Your answer is partially correct. Cake has a pretty robust console system. Look at http://book.cakephp.org/view/110/Creating-Shells-Tasks and http://book.cakephp.org/view/846/Running-Shells-as-cronjobs – Wil Jun 13 '11 at 20:59
  • 1
    @William - Thanks! I had no idea we could do this. – Francois Deschenes Jun 13 '11 at 21:06
1

If you are on Linux or Mac, try Cron:

Community
  • 1
  • 1
TuteC
  • 4,342
  • 30
  • 40
0

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

Vicer
  • 1,034
  • 5
  • 15
  • 22
0

Two things:

For Linux:

https://www.interspire.com/support/kb/questions/298/How+do+I+set+up+CRON+on+my+server%3F

For Windows:

http://troy.jdmz.net/cron/

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.

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66