2

I'm trying to schedule my Controller Method in PHP CodeIgniter; I mean I need to call a controller method on specified times!My server is a Windows Server!

So far I followed the following article (http://amitdhamu.com/blog/automating-php-using-task-scheduler/) which schedules a PHP file (calls whole of the PHP File, but I need to call just a controller method!); then I researched and someone at "Scheduling a controller method by Windows task scheduller" said I can do it by:

php C:\Apache\htdocs\index.php myController <myMethod> <arg1> <arg2>

sample:

php C:\Apache\htdocs\index.php users update

I guess he meant something like :

php C:\xampp\htdocs\Project1\application\controllers\site.php test

Which test method is inside my "site" controller! But this one did not work either!

Could you please how I use schedulig to call a controller method on specified times for a Windows Server?

Thanks

Community
  • 1
  • 1
  • You don't call controllers directly, all requests even CLI requests should go through index.php, so for your case, index.php controller method arg1 arg2 ..etc – ahmad Nov 19 '13 at 12:26

2 Answers2

0

I don't have any experience doing this, but Googling I managed to pull this together:

schtasks /create /tn "Test Cron Job" /tr "C:\PHP5\php.exe -f C:\xampp\htdocs\Project1\application\controllers\site.php" /sc hourly

This will run hourly. I don't think you can specify a specific method, though you can add specific command line arguments.

Sources: http://php.net/manual/en/install.windows.commandline.php and http://drupal.org/node/31506

edwardmp
  • 6,339
  • 5
  • 50
  • 77
  • How if I put my controlller method in a seperate file in another controller class and call it in its constructor? –  Nov 18 '13 at 23:22
  • Yup, putting in separate file might work. You can also use command line arguments (check PHP.net link) to run a specific method. – edwardmp Nov 18 '13 at 23:23
  • Thanks man! But the same thing can be done by Windows task manager! I was looking for the right syntax that someone said here: http://stackoverflow.com/questions/19479494/scheduling-a-controller-method-by-windows-task-scheduller –  Nov 18 '13 at 23:41
  • I think that poster is wrong in thinking it is possible to supply a method. But this command is supposed to create a task in the task manager, but instead of using a GUI you run this command. – edwardmp Nov 18 '13 at 23:43
0

You can download curl(http://curl.haxx.se/) command line util and write a bat file to call your url where the controller method is executed then schedule the bat file in windows.

http://curl.haxx.se/docs/httpscripting.html

This is one of the be easiest way to achieve this.

Nish
  • 1,067
  • 4
  • 17
  • 37