Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kohana -- Command Line

Tags:

php

kohana

I'm trying to "faux-fork" a process (an email being sent via SMTP) in my web application, and the application is built on Kohana.

    $command = 'test/email';
    exec('php index.php '.$command.' > /dev/null/ &', $errors, $response);

I'm getting an error --

Notice: Undefined index: SERVER_NAME

When I look into Kohana's index.php file, I see that it is looking for a variable named SERVER_NAME, but I guess it is coming up NULL because Kohana couldn't detect this value and set it prior to run.

Any ideas how to get Kohana to run via command line?

like image 657
swt83 Avatar asked Jan 25 '10 15:01

swt83


2 Answers

After looking into Kohana3 source code, I found that it has support for cli (system/classes/kohana/cli.php). You can pass 3 options (uri, method, get, post). So:-

$ php index.php --uri="items/list"

would call the list method in Controller_Items.

like image 191
k4ml Avatar answered Oct 27 '22 15:10

k4ml


As far as I know you can't run the kohana files directly in command line because of its bootstrap methods.

You could do 2 things: export all command like functions outside kohana and run them independently.

Something else you could do is running it trough the index.php located in the kohana main folder while passing the $controller, $method variables to it so it ends up at the right object where your code is located:

For kohana 2:

php index.php controller/method/var1/var2

Kohana 3

php index.php --uri=controller/method/var1/var2

Edit: Kohana has a great CLI task runner from version 3.3 onward as official module. For version 3.2 it's still an unofficial module. I suggest you use these because they give a lot of extra options on running from CLI:

  • Kohana 3.2 - https://github.com/Zeelot/kohana-minion
  • Kohana 3.3 - https://github.com/kohana/minion
like image 10
RJD22 Avatar answered Oct 27 '22 17:10

RJD22