tags:

views:

658

answers:

4

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?

A: 

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
RJD22
This isn't true, you *can* run Kohana from the command line. This answer probably shouldn't be accepted.
alex
This answer is both untrue and true. I actually explained that you can't run the kohana files directly. But you can run them trough the index.php like zombor beneath is saying(on of the developers).I agree that I should have phrased it differently. Edited now ^^
RJD22
+3  A: 

And Kohana2 is just "php index.php controller/method/param1/param2/etc"

Kohana was built to run on the CLI as well as web.

zombor
+6  A: 

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.

k4ml
that did it for me, thanks.
mr.b
A: 

For Kohana 3, check out these docs and source.

alex