CodeIgniter Forums

Full Version: [SOLVED] Getting "Windows Scheduled Task"/Cron to Work with CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]RBrowne[/eluser]
I've been spending the last day trying to get this little bugger working, but seem to have hit a bit of a dead end.

Just to set the ground rules I'm running Windows Server 2000 with WAMP and MS SQL Server. Therefore in the end to get my Cron jobs I'll be using the Scheduled Tasks tool of windows - oh the fun!

Now before I can do that, I want to write a bat file to run a php script get a couple of arguments from the php script and then process a little further within the bat file. However, first things first, getting the command line that runs my controller "cron/run_cron_jobs".

Before you all jump to the links of google, the CI Wiki, the CI Forum - I've tried them all, and currently have the Cron bootstrapper currently setup and running to some extent on the server. But if it were working perfectly I wouldn't be here.

My controller's Code is as follows:
Code:
<?php

class Cron extends Controller {

    function __construct()
    {
        echo "Beginning Cron Jobs\n";
        echo "-------------------\n";
        parent::Controller();
    }
    
    function run_cron_jobs() {
        echo "1. Cheque Statements\n";
        // Current date and time:
        $currentDate = time();
        //$currentDate = strtotime('-7 month');
        // Date of the last day of the month
        $lastMonth = strtotime('-1 day',strtotime(date('m', strtotime('1 month', $currentDate)).'/01/'.date('Y', $currentDate).' 00:00:00'));
        
        // Shift 5 days from last day of the month.
        $fiveDay = strtotime('-5 days', $lastMonth);
        $dayInt = date('N', $fiveDay);
        
        // Adjust the dayInt appropriately. If ==7 i.e. Sunday we know that the 'day after' is Monday and there are sufficient working days.
        if ($dayInt == 7) $dayInt = 1;
        else $dayInt = -($dayInt - 1);
        
        // The date of the last Monday of the month, allowing for at least 5 working days following before the end of the month.
        $lastMonday = strtotime($dayInt . ' days', $fiveDay);
        echo "Done!\n";
        exit;
    }
}
?>
Now the problematic line is the parent::Controller() one. When I include this, run_cron_jobs() never gets called, in fact nothing after the parent::Controller() line gets called. When I leave it out, the run_cron_jobs() function gets called.

How do I get it to work with the parent::Controller() line in and still call the other functions?!

Any help on this matter would be appreciated - the headache this is causing is giving me a real headache!

Many thanks in advance,
Rich

El Forum

[eluser]slowgary[/eluser]
Are these conditions happening only by command line? In other words, does the parent::Controller() cause the problem when you're accessing the URL in a browser?

El Forum

[eluser]RBrowne[/eluser]
Just when from the command line. Accessing it via the browser is fine. However, if you thinking I should just call up the IE and direct to the page, that's not a solution. Needs to operate from the command line.

El Forum

[eluser]RBrowne[/eluser]
BUMP?

El Forum

[eluser]slowgary[/eluser]
What about using cURL?

El Forum

[eluser]RBrowne[/eluser]
slowgary:

Thanks for the idea. Turns out it had nothing to do with CodeIgniter, it was the php. I use MS SQL Server and therefore need the extension mssql.dll for CodeIgniter to connect to the DB. Turns out when I was using the php command line it was loading an incorrect php.ini file, with the extension commented out. All this headache over something so simple.

Thanks again!