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

Edit: initially posted this in the wrong location, have posted it here!

Sorry for yet another post, but I've got yet another problem! I'm trying to setup a cronjob that runs via CI. I checked out the associated wiki entry (http://codeigniter.com/wiki/Category:Adv...ronScript/) and found the information there very helpful.

I setup a folder called cron in my root directory, and copied index.php into it (renaming it cron.php), and made the following changes:
    $_SERVER['PATH_INFO'] = '/cron/update_jobs';
$system_folder = "../system";

Where cron and update_jobs are the controller and function being called. However, using the following cronjob command:
Quote:php -q /home/part/public_html/wb/cron/cron.php

I receive the following error:
Quote:Warning: require_once(../system/codeigniter/CodeIgniter.php): failed to open stream: No such file or directory in ]

Now, cron is a folder in the root directory. So ../system _should_ be pointing it in the right direction, but I'm not having any luck! Suggestions?

As for a second question, I found the following suggestion for securing the cron controller on the forum, and wanted input on it:
function Cron() {
        if($_SERVER['SCRIPT_FILENAME'] != '/home/part/public_html/wb/cron/cron.php') exit;
    function _remap($method)
        if( !$this->agent->is_browser() && !$this->agent->is_robot() && !$this->agent->is_mobile()):
            exit('You may not access this file.');

[eluser]Jonathon Hill[/eluser]
I've thought about how to handle cronjobs in CI since I'm going to need to set one up soon for a project soon. What if you simply use wget?

wget http://myapp.com/controller/function

Hi Nial,
I have exactly the same issue occurring here. In my instance I am running the system folder above the web root alongside the public_html dir. My cron job is calling a file from a dir at the same level called ci_cron.
the system_folder var is being declared as '../system' which should be correct but I am getting the same error as yourself
Warning: require_once(../system/codeigniter/CodeIgniter.php): failed to open stream:
Did you get a fix going on your setup?


[eluser]Jonathon Hill[/eluser]
Try checking your current directory. When running from the command line, the current directory is NOT the directory where the file is located, as it is when you are executing the PHP file from the web. Try echoing getcwd(). If you need to set the current directory, use chdir(dir).

Also check out my cron bootstrapper script.

I've done this a few different ways. If security isn't an issue, you can just run
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.
/usr/bin/curl -d "key=F00b4r" http://mysite.com/cron

Then in the cron controller:
function Cron()
    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
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.

[eluser]Jonathon Hill[/eluser]
@nevercraft: have you seen my cron bootstrapper script? It is a small stand-alone file that can be used (without modifying CI) to run any arbitrary controller from the commandline. The desired controller is passed as a command line parameter. It also can log the output of your controller.

@Johnathon: Yes, I actually saw it in the wiki shortly after I started working on the project I mentioned. If memory usage and execution time weren't so crucial for this particular app, I would have used it myself. For 99% of applications though, the extra overhead probably isn't noticeable and your script would certainly work like a charm.

@Mr. Hill

thanks a lot, i was looking for exactly same thing. but what about the case ... if someone hit the same controller/method from web, it'll get executed...

what do you suggest, what kind of security measure we need here?

Have you tried using full serverpaths for redirecting to your system directory? From what I recall, I had problems with ../ before. Using a full server path made them go away.

Theme © iAndrew 2016 - Forum software by © MyBB