Sunny
Sunny

Reputation: 105

Cron Job in Kohana

How do you create a cron job in Kohana? I setup a regular controller which extends off the Controller_Base and I ran the command line: /usr/bin/wget http://domain/controller/custom_cron

But I can't get it to work. It just doesn't execute. No error, nothing. I didn't put any special code in my controller ... just what I need to run my program. So if there is like a special command to call a cron job, I didn't add it (cause I don't know what it would be).

Also, I need it to make MySQL calls so I would need to include the db info and connection and what not (if it doesn't do that automatically). And I work off a custom model. How would I include that (if it doesn't do it automatically).

Thank you.

Upvotes: 1

Views: 2695

Answers (3)

sbuck
sbuck

Reputation: 1864

I had to use cURL as my fire-this-script command in curl

Ex:

30     18     *     *     * curl "http://domain.com/controller/method"

php and wget didn't work, even when calling index.php and adding the uri as suggested above.

Also, FYI, Most transparent way to test this was just running the line from SSH manually to see what the results were. Once I confirmed it was working there, then I put it in the cron.

Upvotes: 0

plasmid87
plasmid87

Reputation: 1471

So if there is like a special command to call a cron job, I didn't add it (cause I don't know what it would be)

Daft question - have you added that wget command to crontab or similar?

If on the other hand you're looking to make a "poor man's cron", you could try creating a hook that runs on every page load and checks the last time the job was run, perhaps storing the last timestamp in a file or database.

Upvotes: 0

zombor
zombor

Reputation: 3257

php /path/to/index.php --uri=controller/action/etc/etc

Calling it like this pretty much makes it act exactly like in a web environment. The only difference is the protocol for requests is 'cli'. You'll need to keep that in mind if you are generating links.

Upvotes: 7

Related Questions