Problems getting cron.php to run automatically

Problems getting cron.php to run automatically

Paul Lovatt -
回帖数:2

The problem

I'm running a new install of Moodle 2.2 and noticed my cron.php was still not working, despite adding the necessary lines to my crontab file.  I am now using putty.exe to try to invoke my cron.php on my 1and1.co.uk shared Linux server and am getting the following messages:

 

I solved the first error by going into my cron.php and commenting out line 56 under the line that says // extra safety.  Presumably in doing so I became less safe somehow.  This removes the error but then I get a second error (shown above).  I do not want to keep going into Moodle files to comment out stuff add infinitum until my cron runs, since I do not know what I am doing.  Does anyone have any clues as to what to do here to get my cron to run automatically?

The offending line in setup.php is line 658 and, starting from line 657, it goes as follows

// Defining the site - aka frontpage course
try {
    $SITE = get_site();
} catch (dml_exception $e) {
    $SITE = null;
    if (empty($CFG->version)) {
        $SITE = new stdClass();
        $SITE->id = 1;
    } else {
        throw $e;
    }
}

What I have done so far:

I have run cron.php from a browser and it runs properly without any error messages at all or undue delays, taking just over one second to run.

I have created a cronTest.php file as suggested in the 1and1 tutorial here http://faq.1and1.com/scripting_languages_supported/cron_jobs/3.html This works fine as described in the tutorial.  I have also added a line to my crontab using PuTTY that invokes this cronTest.php file every 15 mins as desired and it works and I receive the emails on the dot every 15 minutes. 

So I know that cron is able to run properly on my server and that I can invoke the necessary files by adding lines to my crontab file.  The cron.php file is clearly running, and somehow generating these errors.  What is causing the errors and how can I proceed?

PS I added a "cli/" into the above path to my cron.php and the same error results

回复Paul Lovatt

Re: Problems getting cron.php to run automatically

Howard Miller -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像
Powered by PHP/4.4.9

*ancient* version of PHP. Simple as that I expect.

Just to make sure, on the command line, type:
 
/usr/bin/php --version


That's one for your hosting company. The 'web' PHP code and the command-line PHP code are actually completely different so, while this situation is possible, it's quite odd.

You didn't get this far, but ....admin/cli/cron.php is *correct*; without the cli/ will not work.

EDIT:
Google suggests that the cli for php5 is actually called 'php5', so you might want to try (conflicting information) /usr/bin/php5 or perhaps /usr/local/bin/php5

Please let us know and I'll update those docs for 1and1 眨眼
回复Howard Miller

Re: Problems getting cron.php to run automatically

Paul Lovatt -

Solution!!

Right again!

I tried /usr/bin/php5 and got a statement from moodle saying it requires at least php 5.3.2 (whereas the default in use on 1and1.co.uk Linux servers is still 5.2.17 on this date). 

I know that my moodle uses the phpdev setting available on the 1and1 servers to get around this problem, so I tried that and got an error.  No such thing as phpdev.

Then, one for luck, I tried php6 and hey presto! It works! The cron runs without error and reports itself to be running on php 5.4.3.

My logical brain tells me I just need to make one small change to my crontab file (now that I know what that is) and ... watch this space ... it appears to work!

For completeness:

The instruction I have added to my crontab (accessed by using PuTTY) is:

*/15 * * * *    /usr/bin/php6    /full/path/to/my/moodle/admin/cli/cron.php

Hallelujah!

Thanks Howard, you are a genius and a scholar!  I will buy you a pint of whatever is your favourite drink sometime.