Welcome Guest, Not a member yet? Register   Sign In
Cronjob problem
#5

[eluser]nevercraft[/eluser]
I've done this a few different ways. If security isn't an issue, you can just run
Code:
wget http://mysite.com/cron

You need to consider the possibility of someone typing that URL into their browser - its unlikely you'd want to allow someone to fire your cron manually at a random time of day.

If you have cURL available on the server, you can add a little security by adding a post variable.
Code:
/usr/bin/curl -d "key=F00b4r" http://mysite.com/cron

Then in the cron controller:
Code:
function Cron()
{
    parent::Controller();
    if ($_POST['key'] != 'F00b4r') show_404();
}

I recently worked on a project where I needed a cron to run some data extraction and DB related stuff (about 300-500 queries per min/every min). Just to cut back on any unneeded resources, I ended up stripping a few pieces out of CI's core to use only the libraries I needed.

1. http://nevercraft.net/files/ci_cron/cron...ernal.phps
2. http://nevercraft.net/files/ci_cron/cron...oller.phps
These two files trick CI into working right while stripping away some unneeded stuff. File 1 contains constants about your application, so make sure to set them.

3. http://nevercraft.net/files/ci_cron/cont...n_job.phps
This is a standard controller that contains the code for your cron job. Notice: You extend ControllerStripped, not Controller.

4. http://nevercraft.net/files/ci_cron/cron/cronjob.phps
This is the file that will be called by the cron daemon

Files 1, 2, and 4 go in /root/crons or wherever you want. File 3 would go in application/controllers.

Then you simply call the cron via
Code:
php /root/crons/cronjob.php

You might need to make some changes to make it work the way you need it to, but it should point you in the right direction.


Messages In This Thread
Cronjob problem - by El Forum - 06-23-2008, 05:02 PM
Cronjob problem - by El Forum - 06-24-2008, 08:10 AM
Cronjob problem - by El Forum - 09-01-2008, 03:18 PM
Cronjob problem - by El Forum - 09-01-2008, 03:52 PM
Cronjob problem - by El Forum - 09-01-2008, 04:17 PM
Cronjob problem - by El Forum - 09-01-2008, 04:28 PM
Cronjob problem - by El Forum - 09-01-2008, 04:39 PM
Cronjob problem - by El Forum - 10-20-2008, 02:01 AM
Cronjob problem - by El Forum - 10-20-2008, 02:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB