Cron(定时运行守护进程)

来自MoodleDocs
Yucheng Hu讨论 | 贡献2013年8月24日 (六) 06:09的版本 →‎基本讨论
跳转至:导航、​搜索

Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个进程必须定时在后台运行。

Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。

重要:不要尝试忽略在你的 Moodle 站点中设置Cron(定时运行守护进程)。没有这个守护进程,你的站点将不会完全正常工作。

一个特殊的程序(通常称为'cron')被用来定时运行 Moodle 脚本。Moodle 的定时运行脚本可以运行发送邮件,更新 Moodle 报表,RSS,完成活动,发布论坛消息和其他任务。因为不同的任务在 Moodle 系统中不是同时运行的,换句话说,这些任务不是同时被触发的,而是分时被触发的。

定时任务(运行 Moodle 脚本)是基于 Unix 系统的核心组件,这操作系统包括(Linux 和 OSX)。定时任务用户管理所有基于时间的服务。在 Widows 中,也有类似的功能,这个功能在 Windows 中被称为 Windows 任务计划,这个被设置用来按照时间计划来运行。

如果你使用的是共享主机服务,你可以咨询你的服务管理员或者相关文档来配置定时任务。

实际上,计划任务包含当个命令行,这个命令行通常设置在系统中的 cron 激活列表中。在基于 Unix 的操作系统中,这个配置文件被配置在'crontab'中。

基本讨论

针对你使用的操作系统,请对应查看你后面的内容,这部分仅仅讨论一些的基本背景信息。

使用下面 2 步可以对守护进程进行一些有效的配置:

  1. 确定运行的正确命令行
  2. 在你的操作系统中找到正确的位置来存放这个命令

配置 Moodle cron 命令行工作

Moodle has two different ways to deploy cron which use different scripts within the Moodle install. These are as follows...

  1. The CLI (command line interpreter) script. This will be at the path
    /path/to/moodle/admin/cli/cron.php
    If in doubt, this is the correct script to use. This needs to be run by a 'PHP CLI' program on your computer. So the final command may look something like
    /usr/bin/php /path/to/moodle/admin/cli/cron.php
    You can (and should) try this on your command line to see if it works.
  2. The web based script. This needs to be run from a web browser and will be accessed via a web url something like http://your.moodle.site/admin/cron.php. You can find command line based web browser (e.g. wget) so the final command may look like
    /usr/bin/wget http://your.moodle.site/admin/cron.php
    This has the advantage that it can be run from *anywhere*. If you can't get cron to work on your machine it can be run somewhere else.


找到放置你定时运行命令行的正确路径

This really does depend on the system you are using and you should find and read the documentation for your platform or hosting. In most cases getting the Moodle cron to run consists of establishing the correct command (above) and then adding it, and the time to run the command, to some sort of file. This might be either through a specific user interface or by editing the file directly.

If using the CLI version you also need to make sure that the cron process is run as the correct user. This is not an issue with the web version.

Example... installing cron on Ubuntu/Debian Linux. Assuming logged in as root..

use the crontab command to open a crontab editor window for the www-data user. This is the user that Apache (the web server) runs as on Debian based systems

$ crontab -u www-data -e

This will open an editor window. To run the cli cron script every 15 minutes, add the line:

*/15 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php >/dev/null

NOTE: the final >/dev/null sends all the output to the 'bin' and stops you getting an email every 15 minutes.

Setting up cron on your system

Choose the information for your server type:

Here are some more instructions for specific hosts (please check that these are up to date):

Using third party cron service

Besides using cron hosted on your own server, you may use third party cron service (usually called webcron):

  • EasyCron - A webcron service provider that eliminates the need of crontab or other task schedulers to set cron job.

Cron settings in Moodle

There are settings within Moodle that control aspects of cron operation:

Remote cron

Using the 'web based' version of cron it is perfectly ok to place the cron process on a different machine to the Moodle server. For example, the cron service on a Unix server can invoke the cron web 'page' on a Windows based Moodle server.

See also

Using Moodle forum discussions: