什么是Cron?

Some of Moodle's modules require continual checks to perform tasks. For example, Moodle needs to check the discussion forums so it can mail out copies of posts to people who have subscribed. 

The script that does all this is located in the admin directory, and is called cron.php. However, it can not run itself, so you need to set up a mechanism where this script is run regularly (eg every five or ten minutes). This provides a "heartbeat" so that the script can perform functions at periods defined by each module. This kind of regular mechanism is known as a cron service. 

Note that the machine performing the cron does not need to be the same machine that is running Moodle.For example,if you have a limited web hosting service that does not have a cron service,then you might choose to run cron on another server or on your home computer.All that matters is that the cron.php file is called regularly. 



n       如何使Cron,php自动运行?

远程登录(或直接登录)基于Linux系统的服务器进行一些命令操作就可以了。

All that Cpanel does is provide a web interface to a Unix utility known as crontab. If you have a command line, you can set up crontab yourself using the command: 

crontab –e

说明:the "crontab -e" command will put you into the 'vi' editor.

这里的example.com是Moodle网址。服务器上应安装wget。

and then adding one of the above commands like: 

*/30 * * * * wget -q -O /dev/null http://example.com/moodle/admin/cron.php

说明: 

如果需要5分钟运行一次,只要把“30”改为“5”就可以了。

The first five entries are the times to run values, followed by the command to run. The asterisk is a wildard, indicating any time. The above example means run the command wget -q -O /dev/null... every 30 minutes (*/30), every hour (*), every day of the month (*), every month (*), every day of the week (*). 

The "O" of "-O" is the capital letter not zero, and refers the output file destination, in this case "/dev/null" which is a black hole and discards the output. If you want to see the output of your cron.php then enter its url in your browser. 

For beginners, "EDITOR=nano crontab -e" will allow you to edit the crontab using the nano editor. Ubuntu defaults to using the nano editor. 

You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit without saving using ":q!" (without the quotes). Here is an intro to the 'vi' editor. 

posted on 2011-08-16 17:52  敌敌  阅读(750)  评论(0编辑  收藏  举报